Skip to content

Commit 9253863

Browse files
committed
feat(ec2): support EC2Launch v2 user data format for Windows instances
Add UserData.forWindowsV2() factory method that generates EC2Launch v2 YAML-formatted user data for Windows instances. New enums: - Ec2LaunchV2Frequency (ALWAYS, ONCE) - Ec2LaunchV2ScriptType (POWERSHELL, BATCH) - Ec2LaunchV2RunAs (LOCAL_SYSTEM, ADMIN) New interface: - WindowsV2UserDataOptions The generated YAML format uses the executeScript task and supports all standard UserData methods (addCommands, addS3DownloadCommand, addExecuteFileCommand, addSignalOnExitCommand). Closes #36781
1 parent e18b1f4 commit 9253863

File tree

12 files changed

+1161
-57
lines changed

12 files changed

+1161
-57
lines changed

packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.userdata-windows-v2.js.snapshot/cdk.out

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.userdata-windows-v2.js.snapshot/integ-userdata-windows-v2.assets.json

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
1+
{
2+
"Resources": {
3+
"IntegUserdataVpcDE2938ED": {
4+
"Type": "AWS::EC2::VPC",
5+
"Properties": {
6+
"CidrBlock": "10.0.0.0/16",
7+
"EnableDnsHostnames": true,
8+
"EnableDnsSupport": true,
9+
"InstanceTenancy": "default",
10+
"Tags": [
11+
{
12+
"Key": "Name",
13+
"Value": "integ-userdata-windows-v2/IntegUserdataVpc"
14+
}
15+
]
16+
}
17+
},
18+
"IntegUserdataVpcPublicSubnet1Subnet9AE7FE85": {
19+
"Type": "AWS::EC2::Subnet",
20+
"Properties": {
21+
"AvailabilityZone": {
22+
"Fn::Select": [
23+
0,
24+
{
25+
"Fn::GetAZs": ""
26+
}
27+
]
28+
},
29+
"CidrBlock": "10.0.0.0/16",
30+
"MapPublicIpOnLaunch": true,
31+
"Tags": [
32+
{
33+
"Key": "aws-cdk:subnet-name",
34+
"Value": "Public"
35+
},
36+
{
37+
"Key": "aws-cdk:subnet-type",
38+
"Value": "Public"
39+
},
40+
{
41+
"Key": "Name",
42+
"Value": "integ-userdata-windows-v2/IntegUserdataVpc/PublicSubnet1"
43+
}
44+
],
45+
"VpcId": {
46+
"Ref": "IntegUserdataVpcDE2938ED"
47+
}
48+
}
49+
},
50+
"IntegUserdataVpcPublicSubnet1RouteTable7B342D96": {
51+
"Type": "AWS::EC2::RouteTable",
52+
"Properties": {
53+
"Tags": [
54+
{
55+
"Key": "Name",
56+
"Value": "integ-userdata-windows-v2/IntegUserdataVpc/PublicSubnet1"
57+
}
58+
],
59+
"VpcId": {
60+
"Ref": "IntegUserdataVpcDE2938ED"
61+
}
62+
}
63+
},
64+
"IntegUserdataVpcPublicSubnet1RouteTableAssociation724A6375": {
65+
"Type": "AWS::EC2::SubnetRouteTableAssociation",
66+
"Properties": {
67+
"RouteTableId": {
68+
"Ref": "IntegUserdataVpcPublicSubnet1RouteTable7B342D96"
69+
},
70+
"SubnetId": {
71+
"Ref": "IntegUserdataVpcPublicSubnet1Subnet9AE7FE85"
72+
}
73+
}
74+
},
75+
"IntegUserdataVpcPublicSubnet1DefaultRoute8F93CC39": {
76+
"Type": "AWS::EC2::Route",
77+
"Properties": {
78+
"DestinationCidrBlock": "0.0.0.0/0",
79+
"GatewayId": {
80+
"Ref": "IntegUserdataVpcIGWB657C40E"
81+
},
82+
"RouteTableId": {
83+
"Ref": "IntegUserdataVpcPublicSubnet1RouteTable7B342D96"
84+
}
85+
},
86+
"DependsOn": [
87+
"IntegUserdataVpcVPCGWFA86AC6A"
88+
]
89+
},
90+
"IntegUserdataVpcIGWB657C40E": {
91+
"Type": "AWS::EC2::InternetGateway",
92+
"Properties": {
93+
"Tags": [
94+
{
95+
"Key": "Name",
96+
"Value": "integ-userdata-windows-v2/IntegUserdataVpc"
97+
}
98+
]
99+
}
100+
},
101+
"IntegUserdataVpcVPCGWFA86AC6A": {
102+
"Type": "AWS::EC2::VPCGatewayAttachment",
103+
"Properties": {
104+
"InternetGatewayId": {
105+
"Ref": "IntegUserdataVpcIGWB657C40E"
106+
},
107+
"VpcId": {
108+
"Ref": "IntegUserdataVpcDE2938ED"
109+
}
110+
}
111+
},
112+
"WindowsV2InstanceInstanceSecurityGroup94A7E775": {
113+
"Type": "AWS::EC2::SecurityGroup",
114+
"Properties": {
115+
"GroupDescription": "integ-userdata-windows-v2/WindowsV2Instance/InstanceSecurityGroup",
116+
"SecurityGroupEgress": [
117+
{
118+
"CidrIp": "0.0.0.0/0",
119+
"Description": "Allow all outbound traffic by default",
120+
"IpProtocol": "-1"
121+
}
122+
],
123+
"Tags": [
124+
{
125+
"Key": "Name",
126+
"Value": "integ-userdata-windows-v2/WindowsV2Instance"
127+
}
128+
],
129+
"VpcId": {
130+
"Ref": "IntegUserdataVpcDE2938ED"
131+
}
132+
}
133+
},
134+
"WindowsV2InstanceInstanceRoleF59C4BA9": {
135+
"Type": "AWS::IAM::Role",
136+
"Properties": {
137+
"AssumeRolePolicyDocument": {
138+
"Statement": [
139+
{
140+
"Action": "sts:AssumeRole",
141+
"Effect": "Allow",
142+
"Principal": {
143+
"Service": "ec2.amazonaws.com"
144+
}
145+
}
146+
],
147+
"Version": "2012-10-17"
148+
},
149+
"Tags": [
150+
{
151+
"Key": "Name",
152+
"Value": "integ-userdata-windows-v2/WindowsV2Instance"
153+
}
154+
]
155+
}
156+
},
157+
"WindowsV2InstanceInstanceProfile4FD051F5": {
158+
"Type": "AWS::IAM::InstanceProfile",
159+
"Properties": {
160+
"Roles": [
161+
{
162+
"Ref": "WindowsV2InstanceInstanceRoleF59C4BA9"
163+
}
164+
]
165+
}
166+
},
167+
"WindowsV2InstanceF6B067DF": {
168+
"Type": "AWS::EC2::Instance",
169+
"Properties": {
170+
"AvailabilityZone": {
171+
"Fn::Select": [
172+
0,
173+
{
174+
"Fn::GetAZs": ""
175+
}
176+
]
177+
},
178+
"IamInstanceProfile": {
179+
"Ref": "WindowsV2InstanceInstanceProfile4FD051F5"
180+
},
181+
"ImageId": {
182+
"Ref": "SsmParameterValueawsserviceamiwindowslatestWindowsServer2022EnglishFullBaseC96584B6F00A464EAD1953AFF4B05118Parameter"
183+
},
184+
"InstanceType": "t3.micro",
185+
"SecurityGroupIds": [
186+
{
187+
"Fn::GetAtt": [
188+
"WindowsV2InstanceInstanceSecurityGroup94A7E775",
189+
"GroupId"
190+
]
191+
}
192+
],
193+
"SubnetId": {
194+
"Ref": "IntegUserdataVpcPublicSubnet1Subnet9AE7FE85"
195+
},
196+
"Tags": [
197+
{
198+
"Key": "Name",
199+
"Value": "integ-userdata-windows-v2/WindowsV2Instance"
200+
}
201+
],
202+
"UserData": {
203+
"Fn::Base64": "version: \"1.1\"\ntasks:\n- task: executeScript\n inputs:\n - frequency: always\n type: powershell\n runAs: localSystem\n content: |-\n Write-Host \"Hello from EC2Launch v2!\"\n New-Item -Path C:\\test.txt -ItemType File -Force"
204+
}
205+
},
206+
"DependsOn": [
207+
"WindowsV2InstanceInstanceRoleF59C4BA9"
208+
]
209+
}
210+
},
211+
"Parameters": {
212+
"SsmParameterValueawsserviceamiwindowslatestWindowsServer2022EnglishFullBaseC96584B6F00A464EAD1953AFF4B05118Parameter": {
213+
"Type": "AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>",
214+
"Default": "/aws/service/ami-windows-latest/Windows_Server-2022-English-Full-Base"
215+
},
216+
"BootstrapVersion": {
217+
"Type": "AWS::SSM::Parameter::Value<String>",
218+
"Default": "/cdk-bootstrap/hnb659fds/version",
219+
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
220+
}
221+
},
222+
"Rules": {
223+
"CheckBootstrapVersion": {
224+
"Assertions": [
225+
{
226+
"Assert": {
227+
"Fn::Not": [
228+
{
229+
"Fn::Contains": [
230+
[
231+
"1",
232+
"2",
233+
"3",
234+
"4",
235+
"5"
236+
],
237+
{
238+
"Ref": "BootstrapVersion"
239+
}
240+
]
241+
}
242+
]
243+
},
244+
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
245+
}
246+
]
247+
}
248+
}
249+
}

packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.userdata-windows-v2.js.snapshot/integ.json

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)