forked from aliyun/ros-templates
-
Notifications
You must be signed in to change notification settings - Fork 1
/
custom-image-ecs.yml
426 lines (422 loc) · 12.9 KB
/
custom-image-ecs.yml
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
415
416
417
418
419
420
421
422
423
424
425
426
ROSTemplateFormatVersion: '2015-09-01'
Description:
en: This template deploys custom image for single instance, supports creating new
VPC and specifying VPC.
zh-cn: 单实例自定义镜像部署,不带数据盘,带公网IP(支持创建新VPC和指定VPC)。
Conditions:
CreateVpcConditions:
Fn::Equals:
- true
- Ref: WhetherCreateVpc
Parameters:
PayType:
Type: String
Label:
en: ECS Instance Charge Type
zh-cn: 付费类型
AssociationProperty: ChargeType
AssociationPropertyMetadata:
LocaleKey: InstanceChargeType
Default: PostPaid
AllowedValues:
- PostPaid
- PrePaid
PayPeriodUnit:
Type: String
Label:
en: Pay Period Unit
zh-cn: 购买资源时长周期
Description:
en: The long cycle of purchasing resources. <br>Week is a Week and Month is
a Month. <br> The default value is month.<br><b><font color='red'> When ECS
instance types are PrePaid valid </b></font>
zh-cn: 购买资源时长的周期。<br>Week为周,Month为月<br>默认值为月<br><b><font color='red'>当ECS实例类型为PrePaid有效</b></font>
AssociationProperty: PayPeriodUnit
AssociationPropertyMetadata:
Visible:
Condition:
Fn::Not:
Fn::Equals:
- ${PayType}
- PostPaid
Default: Month
AllowedValues:
- Month
- Year
PayPeriod:
Type: Number
Label:
en: Period
zh-cn: 购买资源时长
AssociationProperty: PayPeriod
AssociationPropertyMetadata:
Visible:
Condition:
Fn::Not:
Fn::Equals:
- ${PayType}
- PostPaid
Default: 1
AllowedValues:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
EcsInstanceType:
Type: String
Label:
en: Instance Type
zh-cn: 实例类型
AssociationProperty: ALIYUN::ECS::Instance::InstanceType
AssociationPropertyMetadata:
ZoneId: ${ZoneId}
InstanceChargeType: ${InstanceChargeType}
ZoneId:
Type: String
Label:
en: VSwitch Availability Zone
zh-cn: 交换机可用区
AssociationProperty: ALIYUN::ECS::Instance::ZoneId
WhetherCreateVpc:
Type: Boolean
Label:
en: WhetherCreateVpc
zh-cn: 是否新建VPC
Default: false
VpcCidrBlock:
Type: String
Label:
en: VPC CIDR IPv4 Block
zh-cn: 专有网络IPv4网段
Description:
zh-cn: VPC的ip地址段范围,<br>您可以使用以下的ip地址段或其子网:<br><font color='green'>[10.0.0.0/8]</font><br><font
color='green'>[172.16.0.0/12]</font><br><font color='green'>[192.168.0.0/16]</font>
en: 'The ip address range of the VPC in the CidrBlock form; <br>You can use
the following ip address ranges and their subnets: <br><font color=''green''>[10.0.0.0/8]</font><br><font
color=''green''>[172.16.0.0/12]</font><br><font color=''green''>[192.168.0.0/16]</font>'
AssociationProperty: ALIYUN::VPC::VPC::CidrBlock
AssociationPropertyMetadata:
Visible:
Condition:
Fn::Equals:
- ${WhetherCreateVpc}
- true
Default: 192.168.0.0/16
VSwitchCidrBlock:
Type: String
Label:
en: VSwitch CIDR Block
zh-cn: 交换机子网网段
Description:
zh-cn: 必须属于VPC的子网段。
en: Must belong to the subnet segment of VPC.
AssociationProperty: ALIYUN::VPC::VSwitch::CidrBlock
AssociationPropertyMetadata:
VpcCidrBlock: VpcCidrBlock
Visible:
Condition:
Fn::Equals:
- ${WhetherCreateVpc}
- true
Default: 192.168.1.0/24
VpcId:
Type: String
Label:
en: VPC ID
zh-cn: 专有网络VPC实例ID
AssociationProperty: ALIYUN::ECS::VPC::VPCId
AssociationPropertyMetadata:
Visible:
Condition:
Fn::Equals:
- ${WhetherCreateVpc}
- false
Default: ''
VSwitchId:
Type: String
Label:
en: VSwitch ID
zh-cn: 交换机实例ID
AssociationProperty: ALIYUN::ECS::VSwitch::VSwitchId
AssociationPropertyMetadata:
VpcId: ${VpcId}
ZoneId: ${ZoneId}
Visible:
Condition:
Fn::Equals:
- ${WhetherCreateVpc}
- false
Default: ''
InstancePassword:
Type: String
Label:
en: Instance Password
zh-cn: 实例密码
Description:
en: Server login password, Length 8-30, must contain three(Capital letters,
lowercase letters, numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol
in)
zh-cn: 服务器登录密码,长度8-30,必须包含三项(大写字母、小写字母、数字、 ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ 中的特殊符号)
ConstraintDescription:
en: Length 8-30, must contain three(Capital letters, lowercase letters, numbers,
()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol in)
zh-cn: 长度8-30,必须包含三项(大写字母、小写字母、数字、 ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ 中的特殊符号)
AssociationProperty: ALIYUN::ECS::Instance::Password
AllowedPattern: '[0-9A-Za-z\_\-\&:;''<>,=%`~!@#\(\)\$\^\*\+\|\{\}\[\]\.\?\/]+$'
MinLength: 8
MaxLength: 30
NoEcho: true
SystemDiskCategory:
Type: String
Label:
en: System Disk Category
zh-cn: 系统盘类型
AssociationProperty: ALIYUN::ECS::Disk::SystemDiskCategory
AssociationPropertyMetadata:
LocaleKey: DiskCategory
InstanceType: ${EcsInstanceType}
AllowedValues:
- cloud_efficiency
- cloud_ssd
- cloud_essd
SystemDiskSize:
Type: Number
Label:
zh-cn: 系统盘空间 (GB)
en: System Disk Space (GB)
Default: 200
InternetMaxBandwidthOut:
Type: Number
Label:
zh-cn: 流量公网带宽
en: Internet Max Bandwidth Out
Default: 10
MinValue: 1
MaxValue: 100
Resources:
EcsVpc:
Type: ALIYUN::ECS::VPC
Condition: CreateVpcConditions
Properties:
CidrBlock:
Ref: VpcCidrBlock
VpcName:
Ref: ALIYUN::StackName
EcsVSwitch:
Type: ALIYUN::ECS::VSwitch
Condition: CreateVpcConditions
Properties:
ZoneId:
Ref: ZoneId
VpcId:
Ref: EcsVpc
CidrBlock:
Ref: VSwitchCidrBlock
EcsSecurityGroup:
Type: ALIYUN::ECS::SecurityGroup
Properties:
# 按照软件名称设置安全组名称
#SecurityGroupName: nginx-sg
VpcId:
Fn::If:
- CreateVpcConditions
- Ref: EcsVpc
- Ref: VpcId
# 按照软件监听的端口,设置入方向规则(安全组默认出方向的全部端口都是放行的)
#SecurityGroupIngress:
# - PortRange: 80/80
# Priority: 1
# SourceCidrIp: 0.0.0.0/0
# IpProtocol: tcp
EcsInstanceGroup:
Type: ALIYUN::ECS::InstanceGroup
Properties:
ZoneId:
Ref: ZoneId
VpcId:
Fn::If:
- CreateVpcConditions
- Ref: EcsVpc
- Ref: VpcId
VSwitchId:
Fn::If:
- CreateVpcConditions
- Ref: EcsVSwitch
- Ref: VSwitchId
SecurityGroupId:
Ref: EcsSecurityGroup
ImageId: centos_7
IoOptimized: optimized
InstanceChargeType:
Ref: PayType
PeriodUnit:
Ref: PayPeriodUnit
Period:
Ref: PayPeriod
SystemDiskCategory:
Ref: SystemDiskCategory
# 系统盘大小可以根据需要调整
SystemDiskSize:
Ref: SystemDiskSize
MaxAmount: 1
InstanceType:
Ref: EcsInstanceType
Password:
Ref: InstancePassword
# 设置公网带宽
InternetMaxBandwidthOut:
Ref: InternetMaxBandwidthOut
InstanceName:
Fn::Join:
- '-'
- - Ref: ALIYUN::StackName
- '[1,4]'
# 如果不需要执行命令,请删除WaitCondition、WaitConditionHandle、InstanceRunCommand
WaitConditionHandle:
Type: ALIYUN::ROS::WaitConditionHandle
Properties: {}
WaitCondition:
Type: ALIYUN::ROS::WaitCondition
Properties:
Count: 1
Handle:
Ref: WaitConditionHandle
# 等待命令执行完成的超时时间
Timeout: 300
InstanceRunCommand:
Type: ALIYUN::ECS::RunCommand
Properties:
InstanceIds:
Fn::GetAtt:
- EcsInstanceGroup
- InstanceIds
CommandContent:
Fn::Sub:
- |
#!/bin/bash
# 1. 安装软件,或者对软件进行初始化配置,比如将数据文件目录指定到数据盘目录
# yum install -y nginx
# 2. 如果需要开机自启动,请添加系统服务并启用
# systemctl enable nginx.service
# 3. 配置启动脚本或者启动系统服务
# systemctl start nginx.service
# 4. 执行成功回调WaitCondition结束waitCondition的等待
${CurlCli} -d "{\"Data\" : \"Success\", \"status\" : \"SUCCESS\"}"
# 脚本里任何地方如果发现执行失败,使用以下命令返回FAILURE和错误信息
# ${CurlCli} -d "{\"Data\" : \"error message\", \"status\" : \"FAILURE\"}"
- CurlCli:
Fn::GetAtt:
- WaitConditionHandle
- CurlCli
Type: RunShellScript
Timeout: 300
# outputs是根据软件需求定义
# Outputs are defined according to software requirements
# 以下是以nginx为例,输出了网站公网访问地址
# The following is an example of nginx, which outputs the public network access address of the website
#Outputs:
# endpoint:
# Description:
# zh-cn: 对外暴露的公网IP地址
# en: Public IP Addresses
# Value:
# Fn::Sub:
# - http://${ServerAddress}
# - ServerAddress:
# Fn::Select:
# - 0
# - Fn::GetAtt:
# - EcsInstanceGroup
# - PublicIps
Metadata:
ALIYUN::ROS::Interface:
## 参数组的顺序会确定用户创建服务实例页面的参数排列顺序
## The order of the parameter groups determines the order in which the parameters are arranged on the user creation service instance page
## 如果绝大部分实例规格都适用,比如x86架构,可以按注释中将可用区放在前面选择
## If most of the instance specifications are applicable, such as the x86 architecture, you can select the availability zone in front of the note
# ParameterGroups:
# - Parameters:
# - ZoneId
# Label:
# default:
# zh-cn: 可用区配置
# en: Zone Configuration
# - Parameters:
# - WhetherCreateVpc
# - VpcCidrBlock
# - VSwitchCidrBlock
# - VpcId
# - VSwitchId
# Label:
# default:
# zh-cn: 选择已有基础资源配置
# en: Choose existing Infrastructure Configuration
# - Parameters:
# - PayType
# - PayPeriodUnit
# - PayPeriod
# Label:
# default:
# en: PayType Configuration
# zh-cn: 付费类型配置
# - Parameters:
# - EcsInstanceType
# - InstancePassword
# - SystemDiskCategory
# - SystemDiskSize
# - InternetMaxBandwidthOut
# Label:
# default:
# en: Instance
# zh-cn: ECS实例配置
ParameterGroups:
## 参数组的顺序会确定用户创建服务实例页面的参数排列顺序
## The order of the parameter groups determines the order in which the parameters are arranged on the user creation service instance page
## 此参数组配置将实例规格放在第一位;如果服务可用的实例规格只存在于部分可用区,这种方式可以保证用户先选定目标规格
## This parameter group configuration puts the instance type first; if the instance type available for the service only exists in some availability zones, this method can ensure that the user first selects the target type
- Parameters:
- PayType
- PayPeriodUnit
- PayPeriod
Label:
default:
en: PayType Configuration
zh-cn: 付费类型配置
- Parameters:
- EcsInstanceType
Label:
default:
zh-cn: ECS实例规格配置
en: ECS Instance Type Configuration
- Parameters:
- ZoneId
Label:
default:
zh-cn: 可用区配置
en: Zone Configuration
- Parameters:
- WhetherCreateVpc
- VpcCidrBlock
- VSwitchCidrBlock
- VpcId
- VSwitchId
Label:
default:
zh-cn: 选择已有基础资源配置
en: Choose existing Infrastructure Configuration
- Parameters:
- InstancePassword
- SystemDiskCategory
- SystemDiskSize
- InternetMaxBandwidthOut
Label:
default:
en: Instance
zh-cn: ECS实例详细配置
TemplateTags:
- acs:example:ISV软件部署:创建单ECS实例并部署Nginx