@composurecdk/ec2 0.5.1 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +121 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/instance-builder.d.ts +44 -6
- package/dist/instance-builder.d.ts.map +1 -1
- package/dist/instance-builder.js +49 -4
- package/dist/instance-builder.js.map +1 -1
- package/dist/instance-volume-attachment-config.d.ts +34 -0
- package/dist/instance-volume-attachment-config.d.ts.map +1 -0
- package/dist/instance-volume-attachment-config.js +2 -0
- package/dist/instance-volume-attachment-config.js.map +1 -0
- package/dist/instance-volume-attachment-defaults.d.ts +14 -0
- package/dist/instance-volume-attachment-defaults.d.ts.map +1 -0
- package/dist/instance-volume-attachment-defaults.js +24 -0
- package/dist/instance-volume-attachment-defaults.js.map +1 -0
- package/dist/instance-volume-attachments.d.ts +59 -0
- package/dist/instance-volume-attachments.d.ts.map +1 -0
- package/dist/instance-volume-attachments.js +104 -0
- package/dist/instance-volume-attachments.js.map +1 -0
- package/dist/volume-alarm-config.d.ts +35 -0
- package/dist/volume-alarm-config.d.ts.map +1 -0
- package/dist/volume-alarm-config.js +2 -0
- package/dist/volume-alarm-config.js.map +1 -0
- package/dist/volume-alarm-defaults.d.ts +17 -0
- package/dist/volume-alarm-defaults.d.ts.map +1 -0
- package/dist/volume-alarm-defaults.js +27 -0
- package/dist/volume-alarm-defaults.js.map +1 -0
- package/dist/volume-alarms.d.ts +29 -0
- package/dist/volume-alarms.d.ts.map +1 -0
- package/dist/volume-alarms.js +88 -0
- package/dist/volume-alarms.js.map +1 -0
- package/dist/volume-builder.d.ts +171 -0
- package/dist/volume-builder.d.ts.map +1 -0
- package/dist/volume-builder.js +95 -0
- package/dist/volume-builder.js.map +1 -0
- package/dist/volume-defaults.d.ts +15 -0
- package/dist/volume-defaults.d.ts.map +1 -0
- package/dist/volume-defaults.js +47 -0
- package/dist/volume-defaults.js.map +1 -0
- package/dist/vpc-builder.d.ts +3 -2
- package/dist/vpc-builder.d.ts.map +1 -1
- package/dist/vpc-builder.js +2 -2
- package/dist/vpc-builder.js.map +1 -1
- package/package.json +5 -4
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { AlarmConfig } from "@composurecdk/cloudwatch";
|
|
2
|
+
/**
|
|
3
|
+
* Controls which recommended alarms are created for an EBS volume.
|
|
4
|
+
* All applicable alarms are enabled by default with AWS-recommended
|
|
5
|
+
* thresholds. Set individual alarms to `false` to disable them, or
|
|
6
|
+
* provide an {@link AlarmConfig} to tune thresholds.
|
|
7
|
+
*
|
|
8
|
+
* @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Best_Practice_Recommended_Alarms_AWS_Services.html#EBS
|
|
9
|
+
*/
|
|
10
|
+
export interface VolumeAlarmConfig {
|
|
11
|
+
/**
|
|
12
|
+
* Master switch: set to `false` to disable all recommended alarms.
|
|
13
|
+
* Individual alarms can also be disabled via their own entry.
|
|
14
|
+
* @default true
|
|
15
|
+
*/
|
|
16
|
+
enabled?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Alarm when a burstable volume's I/O credit balance falls low,
|
|
19
|
+
* indicating the volume is about to be throttled to baseline IOPS or
|
|
20
|
+
* throughput.
|
|
21
|
+
*
|
|
22
|
+
* Only created when the configured `volumeType` is one of the burstable
|
|
23
|
+
* types: `gp2` (IOPS credits), `st1` and `sc1` (throughput credits).
|
|
24
|
+
* For non-burstable types (`gp3`, `io1`, `io2`, `standard`) the metric
|
|
25
|
+
* is not emitted, so the alarm is skipped entirely.
|
|
26
|
+
*
|
|
27
|
+
* Metric: `AWS/EBS BurstBalance`, statistic Average, period 5 minutes.
|
|
28
|
+
* Default threshold: < 20% over 3 consecutive 5-minute windows.
|
|
29
|
+
*
|
|
30
|
+
* @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Best_Practice_Recommended_Alarms_AWS_Services.html#EBS
|
|
31
|
+
* @see https://docs.aws.amazon.com/ebs/latest/userguide/general-purpose.html#gp2-volume-performance
|
|
32
|
+
*/
|
|
33
|
+
burstBalance?: AlarmConfig | false;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=volume-alarm-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"volume-alarm-config.d.ts","sourceRoot":"","sources":["../src/volume-alarm-config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAE5D;;;;;;;GAOG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;;;;;;;;;;;;;;OAeG;IACH,YAAY,CAAC,EAAE,WAAW,GAAG,KAAK,CAAC;CACpC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"volume-alarm-config.js","sourceRoot":"","sources":["../src/volume-alarm-config.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { AlarmConfigDefaults } from "@composurecdk/cloudwatch";
|
|
2
|
+
interface VolumeAlarmDefaults {
|
|
3
|
+
enabled: true;
|
|
4
|
+
burstBalance: AlarmConfigDefaults;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* AWS-recommended default alarm configuration for EBS volumes.
|
|
8
|
+
*
|
|
9
|
+
* Thresholds are sourced from the CloudWatch Best Practice Recommended
|
|
10
|
+
* Alarms guide. Thresholds may reasonably be tuned per-workload; defaults
|
|
11
|
+
* bias toward catching obvious issues without excessive noise.
|
|
12
|
+
*
|
|
13
|
+
* @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Best_Practice_Recommended_Alarms_AWS_Services.html#EBS
|
|
14
|
+
*/
|
|
15
|
+
export declare const VOLUME_ALARM_DEFAULTS: VolumeAlarmDefaults;
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=volume-alarm-defaults.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"volume-alarm-defaults.d.ts","sourceRoot":"","sources":["../src/volume-alarm-defaults.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAEpE,UAAU,mBAAmB;IAC3B,OAAO,EAAE,IAAI,CAAC;IACd,YAAY,EAAE,mBAAmB,CAAC;CACnC;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,qBAAqB,EAAE,mBAgBnC,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { TreatMissingData } from "aws-cdk-lib/aws-cloudwatch";
|
|
2
|
+
/**
|
|
3
|
+
* AWS-recommended default alarm configuration for EBS volumes.
|
|
4
|
+
*
|
|
5
|
+
* Thresholds are sourced from the CloudWatch Best Practice Recommended
|
|
6
|
+
* Alarms guide. Thresholds may reasonably be tuned per-workload; defaults
|
|
7
|
+
* bias toward catching obvious issues without excessive noise.
|
|
8
|
+
*
|
|
9
|
+
* @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Best_Practice_Recommended_Alarms_AWS_Services.html#EBS
|
|
10
|
+
*/
|
|
11
|
+
export const VOLUME_ALARM_DEFAULTS = {
|
|
12
|
+
enabled: true,
|
|
13
|
+
/**
|
|
14
|
+
* Burst credit balance is a percentage. Below 20% the volume is
|
|
15
|
+
* approaching throttling to baseline performance — early warning to
|
|
16
|
+
* upsize, switch to a non-burstable type (e.g. `gp3`), or investigate
|
|
17
|
+
* unexpectedly heavy I/O. The 3-of-3 evaluation at 5-minute granularity
|
|
18
|
+
* suppresses transient dips around backup windows.
|
|
19
|
+
*/
|
|
20
|
+
burstBalance: {
|
|
21
|
+
threshold: 20,
|
|
22
|
+
evaluationPeriods: 3,
|
|
23
|
+
datapointsToAlarm: 3,
|
|
24
|
+
treatMissingData: TreatMissingData.NOT_BREACHING,
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=volume-alarm-defaults.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"volume-alarm-defaults.js","sourceRoot":"","sources":["../src/volume-alarm-defaults.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAQ9D;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAwB;IACxD,OAAO,EAAE,IAAI;IAEb;;;;;;OAMG;IACH,YAAY,EAAE;QACZ,SAAS,EAAE,EAAE;QACb,iBAAiB,EAAE,CAAC;QACpB,iBAAiB,EAAE,CAAC;QACpB,gBAAgB,EAAE,gBAAgB,CAAC,aAAa;KACjD;CACF,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type Alarm } from "aws-cdk-lib/aws-cloudwatch";
|
|
2
|
+
import { EbsDeviceVolumeType, type Volume } from "aws-cdk-lib/aws-ec2";
|
|
3
|
+
import type { IConstruct } from "constructs";
|
|
4
|
+
import type { AlarmDefinition } from "@composurecdk/cloudwatch";
|
|
5
|
+
import { AlarmDefinitionBuilder } from "@composurecdk/cloudwatch";
|
|
6
|
+
import type { VolumeAlarmConfig } from "./volume-alarm-config.js";
|
|
7
|
+
/**
|
|
8
|
+
* Resolves the recommended alarm configuration into fully-resolved
|
|
9
|
+
* {@link AlarmDefinition}s, applying contextual logic for the
|
|
10
|
+
* burstable-only credit alarm.
|
|
11
|
+
*/
|
|
12
|
+
export declare function resolveVolumeAlarmDefinitions(volume: Volume, config: VolumeAlarmConfig | undefined, volumeType: EbsDeviceVolumeType | undefined): AlarmDefinition[];
|
|
13
|
+
/**
|
|
14
|
+
* Creates AWS-recommended CloudWatch alarms for an EBS volume,
|
|
15
|
+
* merging recommended definitions with any custom alarm builders.
|
|
16
|
+
*
|
|
17
|
+
* @param scope - CDK construct scope for creating alarm constructs.
|
|
18
|
+
* @param id - Base identifier for alarm construct ids.
|
|
19
|
+
* @param volume - The EBS volume to create alarms for.
|
|
20
|
+
* @param config - User-provided alarm configuration, or `false` to disable all.
|
|
21
|
+
* @param volumeType - Resolved volume type, used to gate the contextual
|
|
22
|
+
* burst-balance alarm.
|
|
23
|
+
* @param customAlarms - Custom alarm builders added via `addAlarm()`.
|
|
24
|
+
* @returns A record mapping alarm keys to their created Alarm constructs.
|
|
25
|
+
*
|
|
26
|
+
* @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Best_Practice_Recommended_Alarms_AWS_Services.html#EBS
|
|
27
|
+
*/
|
|
28
|
+
export declare function createVolumeAlarms(scope: IConstruct, id: string, volume: Volume, config: VolumeAlarmConfig | false | undefined, volumeType: EbsDeviceVolumeType | undefined, customAlarms?: AlarmDefinitionBuilder<Volume>[]): Record<string, Alarm>;
|
|
29
|
+
//# sourceMappingURL=volume-alarms.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"volume-alarms.d.ts","sourceRoot":"","sources":["../src/volume-alarms.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,KAAK,EAAqC,MAAM,4BAA4B,CAAC;AAC3F,OAAO,EAAE,mBAAmB,EAAgB,KAAK,MAAM,EAAE,MAAM,qBAAqB,CAAC;AACrF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,sBAAsB,EAAoC,MAAM,0BAA0B,CAAC;AACpG,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AA4ClE;;;;GAIG;AACH,wBAAgB,6BAA6B,CAC3C,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,iBAAiB,GAAG,SAAS,EACrC,UAAU,EAAE,mBAAmB,GAAG,SAAS,GAC1C,eAAe,EAAE,CAqBnB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,UAAU,EACjB,EAAE,EAAE,MAAM,EACV,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,iBAAiB,GAAG,KAAK,GAAG,SAAS,EAC7C,UAAU,EAAE,mBAAmB,GAAG,SAAS,EAC3C,YAAY,GAAE,sBAAsB,CAAC,MAAM,CAAC,EAAO,GAClD,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAUvB"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { Duration } from "aws-cdk-lib";
|
|
2
|
+
import { ComparisonOperator, Metric, Stats } from "aws-cdk-lib/aws-cloudwatch";
|
|
3
|
+
import { EbsDeviceVolumeType } from "aws-cdk-lib/aws-ec2";
|
|
4
|
+
import { createAlarms, resolveAlarmConfig } from "@composurecdk/cloudwatch";
|
|
5
|
+
import { VOLUME_ALARM_DEFAULTS } from "./volume-alarm-defaults.js";
|
|
6
|
+
/**
|
|
7
|
+
* BurstBalance is published at 5-minute granularity for burstable volume
|
|
8
|
+
* types. A shorter period yields missing data rather than higher resolution.
|
|
9
|
+
*
|
|
10
|
+
* @see https://docs.aws.amazon.com/ebs/latest/userguide/using_cloudwatch_ebs.html
|
|
11
|
+
*/
|
|
12
|
+
const BURST_METRIC_PERIOD = Duration.minutes(5);
|
|
13
|
+
const BURST_METRIC_PERIOD_LABEL = `${String(BURST_METRIC_PERIOD.toMinutes())} minute`;
|
|
14
|
+
/**
|
|
15
|
+
* EBS volume types that publish a `BurstBalance` metric. `gp2` accrues IOPS
|
|
16
|
+
* credits; `st1` and `sc1` accrue throughput credits. Other types
|
|
17
|
+
* (`gp3`, `io1`, `io2`, `standard`) have no burst credit model.
|
|
18
|
+
*
|
|
19
|
+
* @see https://docs.aws.amazon.com/ebs/latest/userguide/using_cloudwatch_ebs.html
|
|
20
|
+
*/
|
|
21
|
+
const BURSTABLE_VOLUME_TYPES = new Set([
|
|
22
|
+
EbsDeviceVolumeType.GP2,
|
|
23
|
+
EbsDeviceVolumeType.ST1,
|
|
24
|
+
EbsDeviceVolumeType.SC1,
|
|
25
|
+
]);
|
|
26
|
+
function isBurstableVolumeType(volumeType) {
|
|
27
|
+
return volumeType !== undefined && BURSTABLE_VOLUME_TYPES.has(volumeType);
|
|
28
|
+
}
|
|
29
|
+
function volumeMetric(volume, metricName, statistic, period) {
|
|
30
|
+
return new Metric({
|
|
31
|
+
namespace: "AWS/EBS",
|
|
32
|
+
metricName,
|
|
33
|
+
dimensionsMap: { VolumeId: volume.volumeId },
|
|
34
|
+
statistic,
|
|
35
|
+
period,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Resolves the recommended alarm configuration into fully-resolved
|
|
40
|
+
* {@link AlarmDefinition}s, applying contextual logic for the
|
|
41
|
+
* burstable-only credit alarm.
|
|
42
|
+
*/
|
|
43
|
+
export function resolveVolumeAlarmDefinitions(volume, config, volumeType) {
|
|
44
|
+
if (config?.enabled === false)
|
|
45
|
+
return [];
|
|
46
|
+
const definitions = [];
|
|
47
|
+
if (config?.burstBalance !== false && isBurstableVolumeType(volumeType)) {
|
|
48
|
+
const cfg = resolveAlarmConfig(config?.burstBalance, VOLUME_ALARM_DEFAULTS.burstBalance);
|
|
49
|
+
definitions.push({
|
|
50
|
+
key: "burstBalance",
|
|
51
|
+
alarmName: cfg.alarmName,
|
|
52
|
+
metric: volumeMetric(volume, "BurstBalance", Stats.AVERAGE, BURST_METRIC_PERIOD),
|
|
53
|
+
threshold: cfg.threshold,
|
|
54
|
+
comparisonOperator: ComparisonOperator.LESS_THAN_THRESHOLD,
|
|
55
|
+
evaluationPeriods: cfg.evaluationPeriods,
|
|
56
|
+
datapointsToAlarm: cfg.datapointsToAlarm,
|
|
57
|
+
treatMissingData: cfg.treatMissingData,
|
|
58
|
+
description: `EBS burstable volume burst credit balance is low — baseline-IOPS throttling is imminent. Threshold: < ${String(cfg.threshold)}% (average) over ${String(cfg.evaluationPeriods)} x ${BURST_METRIC_PERIOD_LABEL}.`,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
return definitions;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Creates AWS-recommended CloudWatch alarms for an EBS volume,
|
|
65
|
+
* merging recommended definitions with any custom alarm builders.
|
|
66
|
+
*
|
|
67
|
+
* @param scope - CDK construct scope for creating alarm constructs.
|
|
68
|
+
* @param id - Base identifier for alarm construct ids.
|
|
69
|
+
* @param volume - The EBS volume to create alarms for.
|
|
70
|
+
* @param config - User-provided alarm configuration, or `false` to disable all.
|
|
71
|
+
* @param volumeType - Resolved volume type, used to gate the contextual
|
|
72
|
+
* burst-balance alarm.
|
|
73
|
+
* @param customAlarms - Custom alarm builders added via `addAlarm()`.
|
|
74
|
+
* @returns A record mapping alarm keys to their created Alarm constructs.
|
|
75
|
+
*
|
|
76
|
+
* @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Best_Practice_Recommended_Alarms_AWS_Services.html#EBS
|
|
77
|
+
*/
|
|
78
|
+
export function createVolumeAlarms(scope, id, volume, config, volumeType, customAlarms = []) {
|
|
79
|
+
if (config === false)
|
|
80
|
+
return {};
|
|
81
|
+
const enabled = config?.enabled ?? VOLUME_ALARM_DEFAULTS.enabled;
|
|
82
|
+
if (!enabled)
|
|
83
|
+
return {};
|
|
84
|
+
const recommended = resolveVolumeAlarmDefinitions(volume, config, volumeType);
|
|
85
|
+
const custom = customAlarms.map((b) => b.resolve(volume));
|
|
86
|
+
return createAlarms(scope, id, [...recommended, ...custom]);
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=volume-alarms.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"volume-alarms.js","sourceRoot":"","sources":["../src/volume-alarms.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAc,kBAAkB,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;A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9D,CAAC"}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { type Alarm } from "aws-cdk-lib/aws-cloudwatch";
|
|
2
|
+
import { Volume, type VolumeProps } from "aws-cdk-lib/aws-ec2";
|
|
3
|
+
import { type IKey } from "aws-cdk-lib/aws-kms";
|
|
4
|
+
import { type IConstruct } from "constructs";
|
|
5
|
+
import { COPY_STATE, type Lifecycle, type Resolvable } from "@composurecdk/core";
|
|
6
|
+
import { type ITaggedBuilder } from "@composurecdk/cloudformation";
|
|
7
|
+
import { AlarmDefinitionBuilder } from "@composurecdk/cloudwatch";
|
|
8
|
+
import type { VolumeAlarmConfig } from "./volume-alarm-config.js";
|
|
9
|
+
/**
|
|
10
|
+
* Configuration properties for the EBS volume builder.
|
|
11
|
+
*
|
|
12
|
+
* Extends the CDK {@link VolumeProps} but lifts the cross-component-wiring
|
|
13
|
+
* props to {@link Resolvable} so they can be supplied as either concrete
|
|
14
|
+
* values or {@link Ref}s to sibling components in a {@link compose}d system:
|
|
15
|
+
*
|
|
16
|
+
* - `availabilityZone` is supplied via the dedicated
|
|
17
|
+
* {@link IVolumeBuilder.availabilityZone | .availabilityZone()} method
|
|
18
|
+
* so it can be wired from a sibling `VpcBuilder`.
|
|
19
|
+
* - `encryptionKey` is exposed on the builder as a `Resolvable<IKey>`
|
|
20
|
+
* setter so a sibling KMS key builder can supply a CMK.
|
|
21
|
+
*
|
|
22
|
+
* Other props (`size`, `volumeType`, `iops`, `throughput`, `enableMultiAttach`,
|
|
23
|
+
* `autoEnableIo`, `removalPolicy`, etc.) are passed through with their CDK
|
|
24
|
+
* types unchanged because they are almost always constructed inline rather
|
|
25
|
+
* than referenced from another component.
|
|
26
|
+
*/
|
|
27
|
+
export interface VolumeBuilderProps extends Omit<VolumeProps, "availabilityZone" | "encryptionKey"> {
|
|
28
|
+
/**
|
|
29
|
+
* Customer-managed KMS key (CMK) used to encrypt the volume.
|
|
30
|
+
*
|
|
31
|
+
* Accepts a concrete {@link IKey} or a {@link Ref} that resolves to one
|
|
32
|
+
* at build time (e.g. a sibling key builder in the same composed system).
|
|
33
|
+
*
|
|
34
|
+
* @default - the account's default EBS KMS key, applied because
|
|
35
|
+
* `encrypted: true` is set in {@link VOLUME_DEFAULTS}.
|
|
36
|
+
*
|
|
37
|
+
* @see https://docs.aws.amazon.com/wellarchitected/latest/security-pillar/sec_protect_data_rest_encrypt.html
|
|
38
|
+
*/
|
|
39
|
+
encryptionKey?: Resolvable<IKey>;
|
|
40
|
+
/**
|
|
41
|
+
* Configuration for AWS-recommended CloudWatch alarms.
|
|
42
|
+
*
|
|
43
|
+
* By default, the builder creates recommended alarms with sensible
|
|
44
|
+
* thresholds for every applicable metric. Individual alarms can be
|
|
45
|
+
* customized or disabled. Set to `false` to disable all alarms.
|
|
46
|
+
*
|
|
47
|
+
* No alarm actions are configured by default since notification methods
|
|
48
|
+
* are user-specific. Access alarms from the build result or use an
|
|
49
|
+
* `afterBuild` hook to apply actions.
|
|
50
|
+
*
|
|
51
|
+
* Contextual alarms (`burstBalance`) are only created when the
|
|
52
|
+
* corresponding volume configuration is present — e.g., a burstable
|
|
53
|
+
* `gp2`/`st1`/`sc1` volume type.
|
|
54
|
+
*
|
|
55
|
+
* @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Best_Practice_Recommended_Alarms_AWS_Services.html#EBS
|
|
56
|
+
*/
|
|
57
|
+
recommendedAlarms?: VolumeAlarmConfig | false;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The build output of a {@link IVolumeBuilder}. Contains the CDK constructs
|
|
61
|
+
* created during {@link Lifecycle.build}, keyed by role.
|
|
62
|
+
*/
|
|
63
|
+
export interface VolumeBuilderResult {
|
|
64
|
+
volume: Volume;
|
|
65
|
+
/**
|
|
66
|
+
* CloudWatch alarms created for the volume, keyed by alarm name.
|
|
67
|
+
*
|
|
68
|
+
* Includes both AWS-recommended alarms and any custom alarms added
|
|
69
|
+
* via {@link IVolumeBuilder.addAlarm}. Access individual alarms by
|
|
70
|
+
* key (e.g., `result.alarms.burstBalance`).
|
|
71
|
+
*
|
|
72
|
+
* No alarm actions are configured — apply them via the result or an
|
|
73
|
+
* `afterBuild` hook.
|
|
74
|
+
*
|
|
75
|
+
* @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Best_Practice_Recommended_Alarms_AWS_Services.html#EBS
|
|
76
|
+
*/
|
|
77
|
+
alarms: Record<string, Alarm>;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* A fluent builder for configuring and creating an AWS EBS volume.
|
|
81
|
+
*
|
|
82
|
+
* Each configuration property from the CDK {@link VolumeProps} is exposed
|
|
83
|
+
* as an overloaded method: call with a value to set it (returns the builder
|
|
84
|
+
* for chaining), or call with no arguments to read the current value.
|
|
85
|
+
*
|
|
86
|
+
* The `availabilityZone` is set via the dedicated
|
|
87
|
+
* {@link IVolumeBuilder.availabilityZone | .availabilityZone()} method that
|
|
88
|
+
* accepts a {@link Resolvable} value for cross-component wiring (e.g., to
|
|
89
|
+
* a sibling {@link IVpcBuilder}). The `encryptionKey` setter likewise
|
|
90
|
+
* accepts a {@link Resolvable} value so a sibling KMS-key builder's output
|
|
91
|
+
* can be supplied via {@link ref}.
|
|
92
|
+
*
|
|
93
|
+
* The builder implements {@link Lifecycle}, so it can be used directly as a
|
|
94
|
+
* component in a {@link compose | composed system}. When built, it creates
|
|
95
|
+
* an EBS volume with the configured properties and returns a
|
|
96
|
+
* {@link VolumeBuilderResult}.
|
|
97
|
+
*
|
|
98
|
+
* AWS-recommended CloudWatch alarms are created by default. Alarms can be
|
|
99
|
+
* customized or disabled via the `recommendedAlarms` property. Custom
|
|
100
|
+
* alarms can be added via the {@link addAlarm} method.
|
|
101
|
+
*
|
|
102
|
+
* @see https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.Volume.html
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```ts
|
|
106
|
+
* const data = createVolumeBuilder()
|
|
107
|
+
* .availabilityZone(ref<VpcBuilderResult>("network").map(r => r.vpc.availabilityZones[0]))
|
|
108
|
+
* .size(Size.gibibytes(50));
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
export type IVolumeBuilder = ITaggedBuilder<VolumeBuilderProps, VolumeBuilder>;
|
|
112
|
+
declare class VolumeBuilder implements Lifecycle<VolumeBuilderResult> {
|
|
113
|
+
#private;
|
|
114
|
+
props: Partial<VolumeBuilderProps>;
|
|
115
|
+
/**
|
|
116
|
+
* Sets the Availability Zone the volume will be created in.
|
|
117
|
+
*
|
|
118
|
+
* Accepts a concrete AZ string or a {@link Ref} that resolves to one at
|
|
119
|
+
* build time. This is how cross-component wiring works — e.g., to a
|
|
120
|
+
* sibling {@link IVpcBuilder} via
|
|
121
|
+
* `ref<VpcBuilderResult>("network").map(r => r.vpc.availabilityZones[0])`.
|
|
122
|
+
*
|
|
123
|
+
* @param availabilityZone - The AZ string or a Ref to one.
|
|
124
|
+
* @returns This builder for chaining.
|
|
125
|
+
*/
|
|
126
|
+
availabilityZone(availabilityZone: Resolvable<string>): this;
|
|
127
|
+
/**
|
|
128
|
+
* Adds a custom CloudWatch alarm to be created alongside the recommended
|
|
129
|
+
* alarms. The provided callback receives an {@link AlarmDefinitionBuilder}
|
|
130
|
+
* scoped to the built {@link Volume}; configure it fluently and return it.
|
|
131
|
+
*
|
|
132
|
+
* @param key - A unique key for the alarm (used to generate the alarm id).
|
|
133
|
+
* @param configure - Callback that configures the alarm definition.
|
|
134
|
+
* @returns This builder for chaining.
|
|
135
|
+
*/
|
|
136
|
+
addAlarm(key: string, configure: (alarm: AlarmDefinitionBuilder<Volume>) => AlarmDefinitionBuilder<Volume>): this;
|
|
137
|
+
/** @internal — see ADR-0005. */
|
|
138
|
+
[COPY_STATE](target: VolumeBuilder): void;
|
|
139
|
+
build(scope: IConstruct, id: string, context?: Record<string, object>): VolumeBuilderResult;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Creates a new {@link IVolumeBuilder} for configuring an AWS EBS volume.
|
|
143
|
+
*
|
|
144
|
+
* This is the entry point for defining an EBS volume component. The
|
|
145
|
+
* returned builder exposes every {@link VolumeBuilderProps} property as a
|
|
146
|
+
* fluent setter/getter, plus
|
|
147
|
+
* {@link IVolumeBuilder.availabilityZone | .availabilityZone()} for
|
|
148
|
+
* cross-component AZ wiring with Ref support. It implements
|
|
149
|
+
* {@link Lifecycle} for use with {@link compose}.
|
|
150
|
+
*
|
|
151
|
+
* @returns A fluent builder for an AWS EBS volume.
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* ```ts
|
|
155
|
+
* const data = createVolumeBuilder()
|
|
156
|
+
* .availabilityZone(ref<VpcBuilderResult>("network").map(r => r.vpc.availabilityZones[0]))
|
|
157
|
+
* .size(Size.gibibytes(50));
|
|
158
|
+
*
|
|
159
|
+
* // Use standalone:
|
|
160
|
+
* const result = data.build(stack, "Data", { network });
|
|
161
|
+
*
|
|
162
|
+
* // Or compose into a system:
|
|
163
|
+
* const system = compose(
|
|
164
|
+
* { network: createVpcBuilder(), data },
|
|
165
|
+
* { network: [], data: ["network"] },
|
|
166
|
+
* );
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
export declare function createVolumeBuilder(): IVolumeBuilder;
|
|
170
|
+
export {};
|
|
171
|
+
//# sourceMappingURL=volume-builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"volume-builder.d.ts","sourceRoot":"","sources":["../src/volume-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,KAAK,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAA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a,GAAG,IAAI;IAKzC,KAAK,CAAC,KAAK,EAAE,UAAU,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,mBAAmB;CAkC5F;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,mBAAmB,IAAI,cAAc,CAEpD"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { Volume } from "aws-cdk-lib/aws-ec2";
|
|
2
|
+
import { COPY_STATE, resolve } from "@composurecdk/core";
|
|
3
|
+
import { taggedBuilder } from "@composurecdk/cloudformation";
|
|
4
|
+
import { AlarmDefinitionBuilder } from "@composurecdk/cloudwatch";
|
|
5
|
+
import { createVolumeAlarms } from "./volume-alarms.js";
|
|
6
|
+
import { VOLUME_DEFAULTS } from "./volume-defaults.js";
|
|
7
|
+
class VolumeBuilder {
|
|
8
|
+
props = {};
|
|
9
|
+
#customAlarms = [];
|
|
10
|
+
#availabilityZone;
|
|
11
|
+
/**
|
|
12
|
+
* Sets the Availability Zone the volume will be created in.
|
|
13
|
+
*
|
|
14
|
+
* Accepts a concrete AZ string or a {@link Ref} that resolves to one at
|
|
15
|
+
* build time. This is how cross-component wiring works — e.g., to a
|
|
16
|
+
* sibling {@link IVpcBuilder} via
|
|
17
|
+
* `ref<VpcBuilderResult>("network").map(r => r.vpc.availabilityZones[0])`.
|
|
18
|
+
*
|
|
19
|
+
* @param availabilityZone - The AZ string or a Ref to one.
|
|
20
|
+
* @returns This builder for chaining.
|
|
21
|
+
*/
|
|
22
|
+
availabilityZone(availabilityZone) {
|
|
23
|
+
this.#availabilityZone = availabilityZone;
|
|
24
|
+
return this;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Adds a custom CloudWatch alarm to be created alongside the recommended
|
|
28
|
+
* alarms. The provided callback receives an {@link AlarmDefinitionBuilder}
|
|
29
|
+
* scoped to the built {@link Volume}; configure it fluently and return it.
|
|
30
|
+
*
|
|
31
|
+
* @param key - A unique key for the alarm (used to generate the alarm id).
|
|
32
|
+
* @param configure - Callback that configures the alarm definition.
|
|
33
|
+
* @returns This builder for chaining.
|
|
34
|
+
*/
|
|
35
|
+
addAlarm(key, configure) {
|
|
36
|
+
this.#customAlarms.push(configure(new AlarmDefinitionBuilder(key)));
|
|
37
|
+
return this;
|
|
38
|
+
}
|
|
39
|
+
/** @internal — see ADR-0005. */
|
|
40
|
+
[COPY_STATE](target) {
|
|
41
|
+
target.#availabilityZone = this.#availabilityZone;
|
|
42
|
+
target.#customAlarms.push(...this.#customAlarms);
|
|
43
|
+
}
|
|
44
|
+
build(scope, id, context) {
|
|
45
|
+
const resolvedAz = this.#availabilityZone
|
|
46
|
+
? resolve(this.#availabilityZone, context)
|
|
47
|
+
: undefined;
|
|
48
|
+
if (resolvedAz === undefined) {
|
|
49
|
+
throw new Error(`VolumeBuilder "${id}" requires an availability zone. ` +
|
|
50
|
+
`Call .availabilityZone() with a string or a Ref to one.`);
|
|
51
|
+
}
|
|
52
|
+
const { recommendedAlarms: alarmConfig, encryptionKey, ...volumeProps } = this.props;
|
|
53
|
+
const mergedProps = {
|
|
54
|
+
...VOLUME_DEFAULTS,
|
|
55
|
+
...volumeProps,
|
|
56
|
+
availabilityZone: resolvedAz,
|
|
57
|
+
...(encryptionKey !== undefined ? { encryptionKey: resolve(encryptionKey, context) } : {}),
|
|
58
|
+
};
|
|
59
|
+
const volume = new Volume(scope, id, mergedProps);
|
|
60
|
+
const alarms = createVolumeAlarms(scope, id, volume, alarmConfig, mergedProps.volumeType, this.#customAlarms);
|
|
61
|
+
return { volume, alarms };
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Creates a new {@link IVolumeBuilder} for configuring an AWS EBS volume.
|
|
66
|
+
*
|
|
67
|
+
* This is the entry point for defining an EBS volume component. The
|
|
68
|
+
* returned builder exposes every {@link VolumeBuilderProps} property as a
|
|
69
|
+
* fluent setter/getter, plus
|
|
70
|
+
* {@link IVolumeBuilder.availabilityZone | .availabilityZone()} for
|
|
71
|
+
* cross-component AZ wiring with Ref support. It implements
|
|
72
|
+
* {@link Lifecycle} for use with {@link compose}.
|
|
73
|
+
*
|
|
74
|
+
* @returns A fluent builder for an AWS EBS volume.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```ts
|
|
78
|
+
* const data = createVolumeBuilder()
|
|
79
|
+
* .availabilityZone(ref<VpcBuilderResult>("network").map(r => r.vpc.availabilityZones[0]))
|
|
80
|
+
* .size(Size.gibibytes(50));
|
|
81
|
+
*
|
|
82
|
+
* // Use standalone:
|
|
83
|
+
* const result = data.build(stack, "Data", { network });
|
|
84
|
+
*
|
|
85
|
+
* // Or compose into a system:
|
|
86
|
+
* const system = compose(
|
|
87
|
+
* { network: createVpcBuilder(), data },
|
|
88
|
+
* { network: [], data: ["network"] },
|
|
89
|
+
* );
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
export function createVolumeBuilder() {
|
|
93
|
+
return taggedBuilder(VolumeBuilder);
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=volume-builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"volume-builder.js","sourceRoot":"","sources":["../src/volume-builder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAoB,MAAM,qBAAqB,CAAC;AAG/D,OAAO,EAAE,UAAU,EAAkB,OAAO,EAAmB,MAAM,oBAAoB,CAAC;AAC1F,OAAO,EAAuB,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAClF,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAElE,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAiHvD,MAAM,aAAa;IACjB,KAAK,GAAgC,EAAE,CAAC;IAC/B,aAAa,GAAqC,EAAE,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AAC;QAEjB,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,KAAK,EAAE,EAAE,EAAE,WAAW,CAAC,CAAC;QAElD,MAAM,MAAM,GAAG,kBAAkB,CAC/B,KAAK,EACL,EAAE,EACF,MAAM,EACN,WAAW,EACX,WAAW,CAAC,UAAU,EACtB,IAAI,CAAC,aAAa,CACnB,CAAC;QAEF,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;IAC5B,CAAC;CACF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,UAAU,mBAAmB;IACjC,OAAO,aAAa,CAAoC,aAAa,CAAC,CAAC;AACzE,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type VolumeProps } from "aws-cdk-lib/aws-ec2";
|
|
2
|
+
/**
|
|
3
|
+
* Secure, AWS-recommended defaults applied to every EBS volume built with
|
|
4
|
+
* {@link createVolumeBuilder}. Each property can be individually overridden
|
|
5
|
+
* via the builder's fluent API.
|
|
6
|
+
*
|
|
7
|
+
* Three properties intentionally have no default — they are application-
|
|
8
|
+
* specific and must be supplied explicitly:
|
|
9
|
+
* - `availabilityZone` (via the builder's `.availabilityZone()` method)
|
|
10
|
+
* - `size`
|
|
11
|
+
* - `iops` / `throughput` (only when opting into a volume type that
|
|
12
|
+
* requires them, e.g. `io1`/`io2`)
|
|
13
|
+
*/
|
|
14
|
+
export declare const VOLUME_DEFAULTS: Partial<VolumeProps>;
|
|
15
|
+
//# sourceMappingURL=volume-defaults.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"volume-defaults.d.ts","sourceRoot":"","sources":["../src/volume-defaults.ts"],"names":[],"mappings":"AACA,OAAO,EAAuB,KAAK,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAE5E;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,eAAe,EAAE,OAAO,CAAC,WAAW,CAkChD,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { RemovalPolicy } from "aws-cdk-lib";
|
|
2
|
+
import { EbsDeviceVolumeType } from "aws-cdk-lib/aws-ec2";
|
|
3
|
+
/**
|
|
4
|
+
* Secure, AWS-recommended defaults applied to every EBS volume built with
|
|
5
|
+
* {@link createVolumeBuilder}. Each property can be individually overridden
|
|
6
|
+
* via the builder's fluent API.
|
|
7
|
+
*
|
|
8
|
+
* Three properties intentionally have no default — they are application-
|
|
9
|
+
* specific and must be supplied explicitly:
|
|
10
|
+
* - `availabilityZone` (via the builder's `.availabilityZone()` method)
|
|
11
|
+
* - `size`
|
|
12
|
+
* - `iops` / `throughput` (only when opting into a volume type that
|
|
13
|
+
* requires them, e.g. `io1`/`io2`)
|
|
14
|
+
*/
|
|
15
|
+
export const VOLUME_DEFAULTS = {
|
|
16
|
+
/**
|
|
17
|
+
* GP3 is the current-generation general-purpose SSD — cheaper and faster
|
|
18
|
+
* than GP2 at equivalent sizes, and matches the root-volume choice in
|
|
19
|
+
* {@link INSTANCE_DEFAULTS}.
|
|
20
|
+
* @see https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/general-purpose.html
|
|
21
|
+
*/
|
|
22
|
+
volumeType: EbsDeviceVolumeType.GP3,
|
|
23
|
+
/**
|
|
24
|
+
* Encrypt the volume at rest. Defaults to the account's default EBS KMS
|
|
25
|
+
* key; pass an `encryptionKey` to use a customer-managed key (CMK) for
|
|
26
|
+
* sensitive workloads per SEC08-BP02.
|
|
27
|
+
* @see https://docs.aws.amazon.com/wellarchitected/latest/security-pillar/sec_protect_data_rest_encrypt.html
|
|
28
|
+
* @see https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSEncryption.html
|
|
29
|
+
*/
|
|
30
|
+
encrypted: true,
|
|
31
|
+
/**
|
|
32
|
+
* When EBS detects inconsistent data on boot it disables I/O until the
|
|
33
|
+
* operator acknowledges. For a persistent data volume the safer default
|
|
34
|
+
* is to let I/O resume so the instance can come up unattended; override
|
|
35
|
+
* to `false` for workloads that prefer to block on potential corruption.
|
|
36
|
+
* @see https://docs.aws.amazon.com/ebs/latest/userguide/monitoring-volume-events.html
|
|
37
|
+
*/
|
|
38
|
+
autoEnableIo: true,
|
|
39
|
+
/**
|
|
40
|
+
* Mirrors `BUCKET_DEFAULTS.removalPolicy`. A destroyed volume is
|
|
41
|
+
* unrecoverable; an orphaned volume is a $/month nuisance. Err on the
|
|
42
|
+
* side of retention — flip to `DESTROY` explicitly for ephemeral data.
|
|
43
|
+
* @see https://docs.aws.amazon.com/wellarchitected/latest/reliability-pillar/rel_planning_for_recovery_back_up_data.html
|
|
44
|
+
*/
|
|
45
|
+
removalPolicy: RemovalPolicy.RETAIN,
|
|
46
|
+
};
|
|
47
|
+
//# sourceMappingURL=volume-defaults.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"volume-defaults.js","sourceRoot":"","sources":["../src/volume-defaults.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,mBAAmB,EAAoB,MAAM,qBAAqB,CAAC;AAE5E;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,eAAe,GAAyB;IACnD;;;;;OAKG;IACH,UAAU,EAAE,mBAAmB,CAAC,GAAG;IAEnC;;;;;;OAMG;IACH,SAAS,EAAE,IAAI;IAEf;;;;;;OAMG;IACH,YAAY,EAAE,IAAI;IAElB;;;;;OAKG;IACH,aAAa,EAAE,aAAa,CAAC,MAAM;CACpC,CAAC"}
|
package/dist/vpc-builder.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { FlowLogDestination, Vpc, type VpcProps } from "aws-cdk-lib/aws-ec2";
|
|
2
2
|
import { type LogGroup } from "aws-cdk-lib/aws-logs";
|
|
3
3
|
import { type IConstruct } from "constructs";
|
|
4
|
-
import { type
|
|
4
|
+
import { type Lifecycle } from "@composurecdk/core";
|
|
5
|
+
import { type ITaggedBuilder } from "@composurecdk/cloudformation";
|
|
5
6
|
import { type ILogGroupBuilder } from "@composurecdk/logs";
|
|
6
7
|
/**
|
|
7
8
|
* Configures how VPC flow logs are handled. Pass `false` to disable flow
|
|
@@ -76,7 +77,7 @@ export interface VpcBuilderResult {
|
|
|
76
77
|
* const network = createVpcBuilder().maxAzs(3).natGateways(3);
|
|
77
78
|
* ```
|
|
78
79
|
*/
|
|
79
|
-
export type IVpcBuilder =
|
|
80
|
+
export type IVpcBuilder = ITaggedBuilder<VpcBuilderProps, VpcBuilder>;
|
|
80
81
|
declare class VpcBuilder implements Lifecycle<VpcBuilderResult> {
|
|
81
82
|
props: Partial<VpcBuilderProps>;
|
|
82
83
|
build(scope: IConstruct, id: string): VpcBuilderResult;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vpc-builder.d.ts","sourceRoot":"","sources":["../src/vpc-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,GAAG,EAAE,KAAK,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC7E,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,
|
|
1
|
+
{"version":3,"file":"vpc-builder.d.ts","sourceRoot":"","sources":["../src/vpc-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,GAAG,EAAE,KAAK,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC7E,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,KAAK,cAAc,EAAiB,MAAM,8BAA8B,CAAC;AAClF,OAAO,EAAyB,KAAK,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAGlF;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,cAAc,GACtB,KAAK,GACL;IACE,gFAAgF;IAChF,WAAW,CAAC,EAAE,kBAAkB,CAAC;IACjC;;;;OAIG;IACH,SAAS,CAAC,EAAE,CAAC,CAAC,EAAE,gBAAgB,KAAK,gBAAgB,CAAC;CACvD,CAAC;AAEN;;;;;;GAMG;AACH,MAAM,WAAW,eAAgB,SAAQ,IAAI,CAAC,QAAQ,EAAE,UAAU,CAAC;IACjE,wFAAwF;IACxF,QAAQ,CAAC,EAAE,cAAc,CAAC;CAC3B;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,GAAG,EAAE,GAAG,CAAC;IAET;;;;;;OAMG;IACH,gBAAgB,CAAC,EAAE,QAAQ,CAAC;CAC7B;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,MAAM,WAAW,GAAG,cAAc,CAAC,eAAe,EAAE,UAAU,CAAC,CAAC;AAItE,cAAM,UAAW,YAAW,SAAS,CAAC,gBAAgB,CAAC;IACrD,KAAK,EAAE,OAAO,CAAC,eAAe,CAAC,CAAM;IAErC,KAAK,CAAC,KAAK,EAAE,UAAU,EAAE,EAAE,EAAE,MAAM,GAAG,gBAAgB;CAgBvD;AA2CD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,gBAAgB,IAAI,WAAW,CAE9C"}
|
package/dist/vpc-builder.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FlowLogDestination, Vpc } from "aws-cdk-lib/aws-ec2";
|
|
2
|
-
import {
|
|
2
|
+
import { taggedBuilder } from "@composurecdk/cloudformation";
|
|
3
3
|
import { createLogGroupBuilder } from "@composurecdk/logs";
|
|
4
4
|
import { VPC_DEFAULTS } from "./vpc-defaults.js";
|
|
5
5
|
const DEFAULT_FLOW_LOG_KEY = "DefaultFlowLog";
|
|
@@ -74,6 +74,6 @@ function resolveFlowLogs(scope, id, cfg) {
|
|
|
74
74
|
* ```
|
|
75
75
|
*/
|
|
76
76
|
export function createVpcBuilder() {
|
|
77
|
-
return
|
|
77
|
+
return taggedBuilder(VpcBuilder);
|
|
78
78
|
}
|
|
79
79
|
//# sourceMappingURL=vpc-builder.js.map
|
package/dist/vpc-builder.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vpc-builder.js","sourceRoot":"","sources":["../src/vpc-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,GAAG,EAAiB,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"vpc-builder.js","sourceRoot":"","sources":["../src/vpc-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,GAAG,EAAiB,MAAM,qBAAqB,CAAC;AAI7E,OAAO,EAAuB,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAClF,OAAO,EAAE,qBAAqB,EAAyB,MAAM,oBAAoB,CAAC;AAClF,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAmFjD,MAAM,oBAAoB,GAAG,gBAAgB,CAAC;AAE9C,MAAM,UAAU;IACd,KAAK,GAA6B,EAAE,CAAC;IAErC,KAAK,CAAC,KAAiB,EAAE,EAAU;QACjC,MAAM,EAAE,QAAQ,EAAE,cAAc,EAAE,GAAG,QAAQ,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;QAE7D,MAAM,EAAE,gBAAgB,EAAE,YAAY,EAAE,GAAG,eAAe,CAAC,KAAK,EAAE,EAAE,EAAE,cAAc,CAAC,CAAC;QAEtF,MAAM,WAAW,GAAG;YAClB,GAAG,YAAY;YACf,GAAG,YAAY;YACf,GAAG,QAAQ;SACZ,CAAC;QAEF,OAAO;YACL,GAAG,EAAE,IAAI,GAAG,CAAC,KAAK,EAAE,EAAE,EAAE,WAAW,CAAC;YACpC,gBAAgB;SACjB,CAAC;IACJ,CAAC;CACF;AAED,SAAS,eAAe,CACtB,KAAiB,EACj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