File tree 3 files changed +40
-1
lines changed
packages/@aws-cdk/aws-ec2
3 files changed +40
-1
lines changed Original file line number Diff line number Diff line change @@ -1073,6 +1073,23 @@ instance.userData.addCommands(
1073
1073
);
1074
1074
```
1075
1075
1076
+ #### Tagging Volumes
1077
+
1078
+ You can configure [ tag propagation on volume creation] ( https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-instance.html#cfn-ec2-instance-propagatetagstovolumeoncreation ) .
1079
+
1080
+ ``` ts
1081
+ declare const vpc: ec2 .Vpc ;
1082
+ declare const instanceType: ec2 .InstanceType ;
1083
+ declare const machineImage: ec2 .IMachineImage ;
1084
+
1085
+ new ec2 .Instance (this , ' Instance' , {
1086
+ vpc ,
1087
+ machineImage ,
1088
+ instanceType ,
1089
+ propagateTagsToVolumeOnCreation: true ,
1090
+ });
1091
+ ```
1092
+
1076
1093
### Configuring Instance Metadata Service (IMDS)
1077
1094
1078
1095
#### Toggling IMDSv1
Original file line number Diff line number Diff line change @@ -214,7 +214,14 @@ export interface InstanceProps {
214
214
*
215
215
* @default - no association
216
216
*/
217
- readonly privateIpAddress ?: string
217
+ readonly privateIpAddress ?: string ;
218
+
219
+ /**
220
+ * Propagate the EC2 instance tags to the EBS volumes.
221
+ *
222
+ * @default - false
223
+ */
224
+ readonly propagateTagsToVolumeOnCreation ?: boolean ;
218
225
219
226
/**
220
227
* Apply the given CloudFormation Init configuration to the instance at startup
@@ -373,6 +380,7 @@ export class Instance extends Resource implements IInstance {
373
380
sourceDestCheck : props . sourceDestCheck ,
374
381
blockDeviceMappings : props . blockDevices !== undefined ? instanceBlockDeviceMappings ( this , props . blockDevices ) : undefined ,
375
382
privateIpAddress : props . privateIpAddress ,
383
+ propagateTagsToVolumeOnCreation : props . propagateTagsToVolumeOnCreation ,
376
384
} ) ;
377
385
this . instance . node . addDependency ( this . role ) ;
378
386
Original file line number Diff line number Diff line change @@ -196,6 +196,20 @@ describe('instance', () => {
196
196
}
197
197
198
198
199
+ } ) ;
200
+ test ( 'can propagate EBS volume tags' , ( ) => {
201
+ // WHEN
202
+ new Instance ( stack , 'Instance' , {
203
+ vpc,
204
+ machineImage : new AmazonLinuxImage ( ) ,
205
+ instanceType : InstanceType . of ( InstanceClass . T3 , InstanceSize . LARGE ) ,
206
+ propagateTagsToVolumeOnCreation : true ,
207
+ } ) ;
208
+
209
+ // THEN
210
+ expect ( stack ) . toHaveResource ( 'AWS::EC2::Instance' , {
211
+ PropagateTagsToVolumeOnCreation : true ,
212
+ } ) ;
199
213
} ) ;
200
214
describe ( 'blockDeviceMappings' , ( ) => {
201
215
test ( 'can set blockDeviceMappings' , ( ) => {
You can’t perform that action at this time.
0 commit comments