-
Notifications
You must be signed in to change notification settings - Fork 17
/
ACS-SMC-CreateAndVerifyInstance.json
414 lines (414 loc) · 21.4 KB
/
ACS-SMC-CreateAndVerifyInstance.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
{
"FormatVersion": "OOS-2019-06-01",
"Description": {
"en": "Create and verify instance by commands",
"zh-cn": "SMC创建并通过执行命令验证目标实例",
"name-en": "ACS-SMC-CreateAndVerifyInstance",
"name-zh-cn": "SMC创建并验证目标实例"
},
"Parameters": {
"regionId": {
"Type": "String",
"Label": {
"en": "RegionId",
"zh-cn": "地域ID"
},
"AssociationProperty": "RegionId",
"Default": "{{ ACS::RegionId }}"
},
"zoneId": {
"Label": {
"en": "ZoneId",
"zh-cn": "可用区"
},
"Description": {
"en": "The target zone id of VSwitch to create",
"zh-cn": "将创建交换机的目标可用区"
},
"AssociationProperty": "ALIYUN::ECS::Instance::ZoneId",
"Type": "String",
"AssociationPropertyMetadata": {
"RegionId": "regionId"
}
},
"hostName": {
"Label": {
"en": "HostName",
"zh-cn": "将创建实例的主机名"
},
"Type": "String",
"AllowedPattern": "^(?!\\.|\\-)(?!.*\\.\\.|.*\\-\\-)(?!.*_).*(?<!\\.|\\-)$",
"MinLength": 2
},
"imageId": {
"Label": {
"en": "ImageId",
"zh-cn": "将创建实例的镜像ID"
},
"Type": "String",
"AssociationProperty": "ALIYUN::ECS::Image::ImageId",
"AssociationPropertyMetadata": {
"RegionId": "regionId"
}
},
"instanceType": {
"Label": {
"en": "InstanceType",
"zh-cn": "将创建实例的规格"
},
"Type": "String",
"AssociationProperty": "ALIYUN::ECS::Instance::InstanceType"
},
"privateIp": {
"Label": {
"en": "PrivateIp",
"zh-cn": "将创建实例的内网IP"
},
"Type": "String"
},
"systemDiskSize": {
"Label": {
"en": "SystemDiskSize",
"zh-cn": "系统盘大小"
},
"Type": "Number",
"Default": 19,
"MinValue": 19,
"MaxValue": 500
},
"instancesCount": {
"Label": {
"en": "InstancesCount",
"zh-cn": "将创建实例的数量"
},
"Type": "Number",
"Default": 1,
"MinValue": 1,
"MaxValue": 999
},
"isDeleteInstance": {
"Label": {
"en": "IsDeleteInstance",
"zh-cn": "检查实例完成后是否删除实例"
},
"Type": "Boolean",
"Default": true
},
"commandType": {
"Label": {
"en": "CommandType",
"zh-cn": "实例自定义检查云助手命令类型"
},
"Type": "String",
"AllowedValues": [
"RunBatScript",
"RunPowerShellScript",
"RunShellScript"
],
"Default": "RunShellScript"
},
"commandContent": {
"Label": {
"en": "CommandContent",
"zh-cn": "实例自定义检查预云助手命令内容"
},
"Type": "String",
"AssociationProperty": "Code",
"Default": ""
},
"timeout": {
"Label": {
"en": "Timeout",
"zh-cn": "执行脚本的超时时间"
},
"Type": "Number",
"Default": 600
},
"workingDir": {
"Label": {
"en": "WorkingDir",
"zh-cn": "在实例中运行命令的目录"
},
"Type": "String",
"Default": "/root"
},
"passwordInherit": {
"Description": {
"en": "To use the PasswordInherit parameter, the Password parameter must be empty and you must make sure that the selected image has a password configured(default:false)",
"zh-cn": "使用该参数时,Password参数必须为空,同时您需要确保使用的镜像已经设置了密码,默认为false"
},
"Label": {
"en": "IsUsePasswordInherit",
"zh-cn": "是否使用镜像预设的密码"
},
"Type": "Boolean",
"Default": false
},
"rateControl": {
"Label": {
"en": "RateControl",
"zh-cn": "任务执行的并发比率"
},
"Type": "Json",
"AssociationProperty": "RateControl",
"Default": {
"Mode": "Concurrency",
"MaxErrors": 0,
"Concurrency": 10
}
},
"OOSAssumeRole": {
"Label": {
"en": "OOSAssumeRole",
"zh-cn": "OOS扮演的RAM角色"
},
"Type": "String",
"Default": ""
}
},
"RamRole": "{{ OOSAssumeRole }}",
"Tasks": [
{
"Name": "describeImages",
"Action": "ACS::ExecuteAPI",
"Description": {
"en": "Query the image ostype by image id",
"zh-cn": "查询镜像的操作系统"
},
"Properties": {
"Service": "ECS",
"API": "DescribeImages",
"Parameters": {
"RegionId": "{{ regionId }}",
"ImageId": "{{ imageId }}"
}
},
"Outputs": {
"osType": {
"ValueSelector": "Images.Image[0].OSType",
"Type": "String"
}
}
},
{
"Name": "converConstant",
"Action": "ACS::ECS::SMCConversionConstantByJqScript",
"Description": {
"en": "Automatically convert to available CidrBlock according to PrivateIp",
"zh-cn": "根据PrivateIp自动转换成可用的CidrBlock"
},
"Properties": {
"parameter": "{{ privateIp }}",
"jqScript": [
".[0] | split(\".\") as $item | $item | if .[0]==\"10\" then \"10.0.0.0/8\" elif .[0]==\"172\" then \"172.16.0.0/12\" elif .[0]==\"192\" then \"192.168.0.0/16\" else \"\" end",
".[0] | split(\".\") as $item | $item | if .[0]==\"10\" then \"10.\"+.[1]+\".0.0/16\" elif .[0]==\"172\" then \"172.\"+.[1]+\".\"+.[2]+\".0/24\" elif .[0]==\"192\" then \"192.168.\"+.[2]+\".0/24\" else \"\" end"
]
},
"Outputs": {
"vswCidrBlock": {
"Type": "String",
"ValueSelector": "secondValue"
},
"vpcCidrBlock": {
"Type": "String",
"ValueSelector": "firstValue"
}
}
},
{
"Name": "createStack",
"Action": "ACS::ExecuteAPI",
"Description": {
"en": "Create a resource stack",
"zh-cn": "创建资源栈"
},
"Properties": {
"Service": "ROS",
"API": "CreateStack",
"Parameters": {
"RegionId": "{{ regionId }}",
"StackName": "OOS-{{ACS::ExecutionId}}",
"TimeoutInMinutes": 10,
"DisableRollback": false,
"Parameters": [
{
"ParameterKey": "hostName",
"ParameterValue": "{{ hostName }}"
},
{
"ParameterKey": "privateIp",
"ParameterValue": "{{ privateIp }}"
},
{
"ParameterKey": "instanceType",
"ParameterValue": "{{ instanceType }}"
},
{
"ParameterKey": "zoneId",
"ParameterValue": "{{ zoneId }}"
},
{
"ParameterKey": "regionId",
"ParameterValue": "{{ regionId }}"
},
{
"ParameterKey": "imageId",
"ParameterValue": "{{imageId}}"
},
{
"ParameterKey": "executionId",
"ParameterValue": "{{ ACS::ExecutionId }}"
},
{
"ParameterKey": "instancesCount",
"ParameterValue": "{{ instancesCount }}"
},
{
"ParameterKey": "systemDiskSize",
"ParameterValue": "{{ systemDiskSize }}"
},
{
"ParameterKey": "passwordInherit",
"ParameterValue": "{{ passwordInherit }}"
}
],
"TemplateBody": {
"Fn::If": [
{
"Fn::Equals": [
"windows",
"{{ describeImages.osType }}"
]
},
"{\n \"Description\": \"Create VPC ECS instance\",\n \"Parameters\": {\n \"imageId\": {\n \"Type\": \"String\"\n },\n \"hostName\": {\n \"Type\": \"String\"\n },\n \"privateIp\": {\n \"Type\": \"String\"\n },\n \"instanceType\": {\n \"Type\": \"String\"\n },\n \"executionId\": {\n \"Type\": \"String\"\n },\n \"instancesCount\": {\n \"Type\": \"String\"\n },\n \"zoneId\": {\n \"Type\": \"String\"\n },\n \"regionId\": {\n \"Type\": \"String\"\n },\n \"systemDiskSize\": {\n \"Type\": \"Number\"\n },\n \"passwordInherit\": {\n \"Type\": \"Boolean\"\n },\n \"resourcePrefix\": {\n \"Type\": \"String\",\n \"Default\": \"oos-generated\"\n }\n },\n \"Conditions\":{\n \"CreateSystemDiskSize\":{\n \"Fn::Equals\":[\n 19,\n {\n \"Ref\":\"systemDiskSize\"\n }\n ]\n }\n },\n \"ROSTemplateFormatVersion\": \"2015-09-01\",\n \"Outputs\": {\n \"ecs_instance_id\": {\n \"Value\": {\n \"Fn::GetAtt\": [\n \"ecs\",\n \"InstanceIds\"\n ]\n }\n }\n },\n \"Resources\": {\n \"vswitch\": {\n \"Type\": \"ALIYUN::ECS::VSwitch\",\n \"Properties\": {\n \"VpcId\": {\n \"Ref\": \"vpc\"\n },\n \"Description\": {\n \"Fn::Join\": [\n \" \",\n [\n \"OOS execution id is\",\n {\n \"Ref\": \"executionId\"\n }\n ]\n ]\n },\n \"ZoneId\": {\n \"Ref\": \"zoneId\"\n },\n \"CidrBlock\": \"{{ converConstant.vswCidrBlock }}\"\n }\n },\n \"sg\": {\n \"Type\": \"ALIYUN::ECS::SecurityGroup\",\n \"Properties\": {\n \"Tags\": [\n {\n \"Key\": \"oos-generated\",\n \"Value\": {\n \"Ref\": \"executionId\"\n }\n },\n {\n \"Key\": \"region\",\n \"Value\": {\n \"Ref\": \"regionId\"\n }\n }\n ],\n \"VpcId\": {\n \"Ref\": \"vpc\"\n },\n \"SecurityGroupName\": {\n \"Fn::Join\": [\n \"-\",\n [\n {\n \"Ref\": \"resourcePrefix\"\n },\n \"sg\"\n ]\n ]\n },\n \"SecurityGroupEgress\": [\n {\n \"PortRange\": \"-1/-1\",\n \"Priority\": 1,\n \"IpProtocol\": \"all\",\n \"DestCidrIp\": \"0.0.0.0/0\",\n \"NicType\": \"intranet\"\n }\n ],\n \"SecurityGroupIngress\": [\n {\n \"PortRange\": \"3389/3389\",\n \"Priority\": 1,\n \"IpProtocol\": \"tcp\",\n \"SourceCidrIp\": \"0.0.0.0/0\",\n \"NicType\": \"intranet\"\n }\n ]\n }\n },\n \"vpc\": {\n \"Type\": \"ALIYUN::ECS::VPC\",\n \"Properties\": {\n \"CidrBlock\": \"{{ converConstant.vpcCidrBlock }}\",\n \"Description\": {\n \"Fn::Join\": [\n \" \",\n [\n \"OOS execution id is\",\n {\n \"Ref\": \"executionId\"\n }\n ]\n ]\n },\n \"VpcName\": {\n \"Fn::Join\": [\n \"-\",\n [\n {\n \"Ref\": \"resourcePrefix\"\n },\n \"vpc\"\n ]\n ]\n }\n }\n },\n \"ecs\": {\n \"Type\": \"ALIYUN::ECS::InstanceGroup\",\n \"Properties\": {\n \"ImageId\": {\n \"Ref\": \"imageId\"\n },\n \"HostName\": {\n \"Ref\": \"hostName\"\n },\n \"PrivateIpAddress\": {\n \"Ref\": \"privateIp\"\n },\n \"SecurityGroupId\": {\n \"Ref\": \"sg\"\n },\n \"VpcId\": {\n \"Ref\": \"vpc\"\n },\n \"VSwitchId\": {\n \"Ref\": \"vswitch\"\n },\n \"InstanceType\": {\n \"Ref\": \"instanceType\"\n },\n \"PasswordInherit\": {\n \"Ref\": \"passwordInherit\"\n },\n \"SystemDiskSize\": {\n \"Fn::If\": [\n \"CreateSystemDiskSize\",\n {\n \"Ref\": \"ALIYUN::NoValue\"\n },\n {\n \"Ref\": \"systemDiskSize\"\n }\n ]\n },\n \"MinAmount\": {\n \"Ref\": \"instancesCount\"\n },\n \"MaxAmount\": {\n \"Ref\": \"instancesCount\"\n },\n \"Tags\": [\n {\n \"Key\": \"oos-generated\",\n \"Value\": {\n \"Ref\": \"executionId\"\n }\n },\n {\n \"Key\": \"region\",\n \"Value\": {\n \"Ref\": \"regionId\"\n }\n }\n ]\n }\n }\n },\n \"Metadata\": {\n \"ALIYUN::ROS::Interface\": {\n \"TemplateTags\": [\n \"acs:integrate:oos:smc_create_and_verify_instance\"\n ]\n }\n }\n}\n",
"{\n \"Description\": \"Create VPC ECS instance\",\n \"Parameters\": {\n \"imageId\": {\n \"Type\": \"String\"\n },\n \"hostName\": {\n \"Type\": \"String\"\n },\n \"privateIp\": {\n \"Type\": \"String\"\n },\n \"instanceType\": {\n \"Type\": \"String\"\n },\n \"passwordInherit\": {\n \"Type\": \"Boolean\"\n },\n \"executionId\": {\n \"Type\": \"String\"\n },\n \"instancesCount\": {\n \"Type\": \"String\"\n },\n \"zoneId\": {\n \"Type\": \"String\"\n },\n \"regionId\": {\n \"Type\": \"String\"\n },\n \"systemDiskSize\": {\n \"Type\": \"Number\"\n },\n \"resourcePrefix\": {\n \"Type\": \"String\",\n \"Default\": \"oos-generated\"\n }\n },\n \"Conditions\":{\n \"CreateSystemDiskSize\":{\n \"Fn::Equals\":[\n 19,\n {\n \"Ref\":\"systemDiskSize\"\n }\n ]\n }\n },\n \"ROSTemplateFormatVersion\": \"2015-09-01\",\n \"Outputs\": {\n \"ecs_instance_id\": {\n \"Value\": {\n \"Fn::GetAtt\": [\n \"ecs\",\n \"InstanceIds\"\n ]\n }\n }\n },\n \"Resources\": {\n \"vswitch\": {\n \"Type\": \"ALIYUN::ECS::VSwitch\",\n \"Properties\": {\n \"VpcId\": {\n \"Ref\": \"vpc\"\n },\n \"Description\": {\n \"Fn::Join\": [\n \" \",\n [\n \"OOS execution id is\",\n {\n \"Ref\": \"executionId\"\n }\n ]\n ]\n },\n \"ZoneId\": {\n \"Ref\": \"zoneId\"\n },\n \"CidrBlock\": \"{{ converConstant.vswCidrBlock }}\"\n }\n },\n \"sg\": {\n \"Type\": \"ALIYUN::ECS::SecurityGroup\",\n \"Properties\": {\n \"Tags\": [\n {\n \"Key\": \"oos-generated\",\n \"Value\": {\n \"Ref\": \"executionId\"\n }\n },\n {\n \"Key\": \"region\",\n \"Value\": {\n \"Ref\": \"regionId\"\n }\n }\n ],\n \"VpcId\": {\n \"Ref\": \"vpc\"\n },\n \"SecurityGroupName\": {\n \"Fn::Join\": [\n \"-\",\n [\n {\n \"Ref\": \"resourcePrefix\"\n },\n \"sg\"\n ]\n ]\n },\n \"SecurityGroupEgress\": [\n {\n \"PortRange\": \"-1/-1\",\n \"Priority\": 1,\n \"IpProtocol\": \"all\",\n \"DestCidrIp\": \"0.0.0.0/0\",\n \"NicType\": \"intranet\"\n }\n ],\n \"SecurityGroupIngress\": [\n {\n \"PortRange\": \"22/22\",\n \"Priority\": 1,\n \"IpProtocol\": \"tcp\",\n \"SourceCidrIp\": \"0.0.0.0/0\",\n \"NicType\": \"intranet\"\n }\n ]\n }\n },\n \"vpc\": {\n \"Type\": \"ALIYUN::ECS::VPC\",\n \"Properties\": {\n \"CidrBlock\": \"{{ converConstant.vpcCidrBlock }}\",\n \"Description\": {\n \"Fn::Join\": [\n \" \",\n [\n \"OOS execution id is\",\n {\n \"Ref\": \"executionId\"\n }\n ]\n ]\n },\n \"VpcName\": {\n \"Fn::Join\": [\n \"-\",\n [\n {\n \"Ref\": \"resourcePrefix\"\n },\n \"vpc\"\n ]\n ]\n }\n }\n },\n \"ecs\": {\n \"Type\": \"ALIYUN::ECS::InstanceGroup\",\n \"Properties\": {\n \"ImageId\": {\n \"Ref\": \"imageId\"\n },\n \"HostName\": {\n \"Ref\": \"hostName\"\n },\n \"PrivateIpAddress\": {\n \"Ref\": \"privateIp\"\n },\n \"SecurityGroupId\": {\n \"Ref\": \"sg\"\n },\n \"VpcId\": {\n \"Ref\": \"vpc\"\n },\n \"VSwitchId\": {\n \"Ref\": \"vswitch\"\n },\n \"InstanceType\": {\n \"Ref\": \"instanceType\"\n },\n \"PasswordInherit\": {\n \"Ref\": \"passwordInherit\"\n },\n \"SystemDiskSize\": {\n \"Fn::If\": [\n \"CreateSystemDiskSize\",\n {\n \"Ref\": \"ALIYUN::NoValue\"\n },\n {\n \"Ref\": \"systemDiskSize\"\n }\n ]\n },\n \"MinAmount\": {\n \"Ref\": \"instancesCount\"\n },\n \"MaxAmount\": {\n \"Ref\": \"instancesCount\"\n },\n \"Tags\": [\n {\n \"Key\": \"oos-generated\",\n \"Value\": {\n \"Ref\": \"executionId\"\n }\n },\n {\n \"Key\": \"region\",\n \"Value\": {\n \"Ref\": \"regionId\"\n }\n }\n ]\n }\n }\n },\n \"Metadata\": {\n \"ALIYUN::ROS::Interface\": {\n \"TemplateTags\": [\n \"acs:integrate:oos:smc_create_and_verify_instance\"\n ]\n }\n }\n}\n"
]
}
}
},
"Outputs": {
"StackId": {
"Type": "String",
"ValueSelector": "StackId"
}
}
},
{
"Name": "untilStackReady",
"Action": "ACS::WaitFor",
"Description": {
"en": "Wait for the stack status CREATE_COMPLETE",
"zh-cn": "等待资源栈至创建成功状态"
},
"OnSuccess": "doInstanceCheck",
"OnError": "queryStackStatusReason",
"Properties": {
"Service": "ROS",
"API": "GetStack",
"Parameters": {
"RegionId": "{{ regionId }}",
"StackId": "{{createStack.StackId}}"
},
"DesiredValues": [
"CREATE_COMPLETE"
],
"StopRetryValues": [
"CREATE_FAILED",
"CHECK_FAILED",
"ROLLBACK_FAILED",
"ROLLBACK_COMPLETE",
"CREATE_ROLLBACK_COMPLETE"
],
"PropertySelector": "Status"
},
"Outputs": {
"instanceIds": {
"Type": "String",
"ValueSelector": "Outputs[0].OutputValue"
}
}
},
{
"Name": "doInstanceCheck",
"Action": "ACS::ECS::SMCVerifyInstanceByRunCommand",
"OnSuccess": "ACS::END",
"OnError": "deleteStack",
"Description": {
"en": "Execute cloud assistant command to check Instance",
"zh-cn": "执行云助手命令检查实例"
},
"Properties": {
"regionId": "{{ regionId }}",
"instanceId": "{{ ACS::TaskLoopItem }}",
"isDeleteInstance": "{{ isDeleteInstance }}",
"commandContent": "{{ commandContent }}",
"commandType": "{{ commandType }}",
"workingDir": "{{ workingDir }}",
"timeout": "{{ timeout }}"
},
"Outputs": {
"commandOutput": {
"Type": "String",
"ValueSelector": "invocationOutput"
}
},
"Loop": {
"RateControl": "{{ rateControl }}",
"Items": "{{ untilStackReady.instanceIds }}",
"Outputs": {
"commandOutputs": {
"AggregateType": "Fn::ListJoin",
"AggregateField": "commandOutput"
}
}
}
},
{
"Name": "queryStackStatusReason",
"Action": "ACS::ExecuteAPI",
"Description": {
"en": "Query the reson of failed created stack",
"zh-cn": "查询资源栈未创建成功的原因"
},
"OnError": "deleteStack",
"OnSuccess": "deleteStack",
"Properties": {
"Service": "ROS",
"API": "GetStack",
"Parameters": {
"RegionId": "{{ regionId }}",
"StackId": "{{ createStack.StackId }}"
}
},
"Outputs": {
"statusReason": {
"Type": "String",
"ValueSelector": "StatusReason"
}
}
},
{
"Name": "deleteStack",
"Description": {
"en": "Delete the stack",
"zh-cn": "删除资源栈"
},
"OnSuccess": "ACS::END",
"Action": "ACS::ExecuteApi",
"Properties": {
"Service": "ROS",
"API": "DeleteStack",
"Parameters": {
"RegionId": "{{ regionId }}",
"StackId": "{{createStack.StackId}}"
}
}
}
],
"Outputs": {
"instanceCheckResults": {
"Type": "List",
"Value": "{{ doInstanceCheck.commandOutputs }}"
}
}
}