This topic helps you walk through the process of creating a Resource Orchestration Service (ROS) template. In this topic, a template that declares the resources used to create an Elastic Compute Service (ECS) instance group and attach the instance group to a Classic Load Balancer (CLB) instance is created.
Prerequisites
You are familiar with the syntax and the structure of ROS templates. For more information, see Getting started with templates.
Sample scenario
In this scenario, an ECS instance group is created in a virtual private cloud (VPC), the Nginx service is deployed in the instance group, and then the instance group is attached to a CLB instance.
Usage notes
You can view the resource types of the preceding resources to obtain the details of each resource property. For more information, see View resource types.
A resource type declares the properties of a resource, such as the type, whether required, and whether editable. If a property is required, you must declare the property in the Properties part of the Resources section of a template. If a property is optional, you can leave the property empty. If a property is editable, you can modify the property in a new template after the property is specified for a cloud resource in a stack template. Then, you can use the new template to update the stack and the resource. Otherwise, you cannot modify the property.
Create a template
Refer to the documentation of resource types to find the resource types that are suitable for your scenario. For more information, see List of resource types by service.
In the sample scenario, you must create resources by using the following resource types: ALIYUN::ECS::VPC (creates a VPC), ALIYUN::ECS::InstanceGroup (creates an ECS instance group), ALIYUN::SLB::LoadBalancer (creates a CLB instance), ALIYUN::SLB::Listener (adds a listener to the CLB instance), ALIYUN::VPC::EIP (creates an EIP, which is abbreviated from elastic IP address), ALIYUN::ECS::VSwitch (creates a vSwitch to which the ECS instance group is connected), and ALIYUN::ECS::InstanceGroup (creates a security group). When you use the ALIYUN::ECS::InstanceGroup resource type to create an ECS instance group, you must use the UserData property of the resource type to run scripts for data initialization. You must also use the ALIYUN::ROS::WaitCondition (waits for a signal) and ALIYUN::ROS::WaitConditionHandle (receives a signal) resource types to control the execution process in the ECS instance group.
You can specify the preceding resource types in the Resources section of the template.
Define and associate resources in the template
Define Vpc, VSwitch, and EcsSecurityGroup
Define the following basic network resources in the template: Vpc
, VSwitch
, and EcsSecurityGroup
.
Use the Ref function together with the ALIYUN::StackName pseudo parameter to obtain the stack name. Then, set a property to Ref: ALIYUN::StackName to associate the property value with the stack name. In the following code snippet, the value of
VpcName
inVpc
and the value ofVSwitchName
inVSwitch
are associated with the stack name. For more information, see Functions and ALIYUN::StackName.Use the Ref function to return the value of a specified parameter. In the following code snippet, Ref: Vpc is specified in
VSwitch
to return the VPC ID that is parsed fromVpc
as the value ofVpcId
. In most cases, Ref returns a resource ID. For more information, see Functions.
Resources:
Vpc:
Type: ALIYUN::ECS::VPC
Properties:
CidrBlock: 192.168.0.0/16
VpcName:
Ref: ALIYUN::StackName
VSwitch:
Type: ALIYUN::ECS::VSwitch
Properties:
VSwitchName:
Ref: ALIYUN::StackName
VpcId:
Ref: Vpc
ZoneId:
Ref: ZoneId
CidrBlock: 192.168.0.0/24
EcsSecurityGroup:
Type: ALIYUN::ECS::SecurityGroup
Properties:
SecurityGroupName:
Ref: ALIYUN::StackName
VpcId:
Ref: Vpc
SecurityGroupIngress:
- PortRange: 80/80
Priority: 1
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
NicType: internet
SecurityGroupEgress:
- PortRange: '-1/-1'
Priority: 1
IpProtocol: all
DestCidrIp: 0.0.0.0/0
NicType: internet
- PortRange: '-1/-1'
Priority: 1
IpProtocol: all
DestCidrIp: 0.0.0.0/0
NicType: intranet
Define Slb, SlbListener, and EipSlbAddress
Define the following resources in the template: Slb
(specifies a CLB instance) ,SlbListener
(specifies a listener), and EipSlbAddress
(specifies an EIP).
Use the Fn::Sub function and the ALIYUN::StackName pseudo parameter to substitute the variable in an input string with the stack name that you obtain. Then, use the new string as the value of a property. For more information, see ALIYUN::StackName.
Resources:
Slb:
Type: ALIYUN::SLB::LoadBalancer
Properties:
VpcId:
Ref: Vpc
VSwitchId:
Ref: VSwitch
LoadBalancerName:
Fn::Sub: slb-${ALIYUN::StackName}
PayType:
Ref: PayType
PricingCycle:
Ref: PayPeriodUnit
Duration:
Ref: PayPeriod
AddressType: intranet
LoadBalancerSpec:
Ref: LoadBalancerSpec
AutoPay: true
SlbListener:
DependsOn:
- Slb
Type: ALIYUN::SLB::Listener
Properties:
Persistence:
CookieTimeout: 60
StickySession: 'on'
PersistenceTimeout: 180
XForwardedFor: 'off'
StickySessionType: insert
ListenerPort: 80
Bandwidth: -1
HealthCheck:
HttpCode: http_2xx,http_3xx,http_4xx,http_5xx
HealthCheckType: tcp
UnhealthyThreshold: 3
Timeout: 5
HealthyThreshold: 3
Port: 80
URI: /
Interval: 2
LoadBalancerId:
Ref: Slb
BackendServerPort: 80
Protocol: tcp
EipSlbAddress:
Type: ALIYUN::VPC::EIP
Properties:
Name:
Ref: ALIYUN::StackName
InternetChargeType: PayByTraffic
Bandwidth:
Ref: Bandwidth
Define EcsInstanceGroup, WaitCondition, and WaitConditionHandle
Define the following resources in the template: EcsInstanceGroup
(specifies an ECS instance group), WaitCondition
(waits for a signal), and WaitConditionHandle
(receives a signal).
Use the Fn::GetAtt function to return the property value of a resource. In the following code snippet, the value of
CurlCli
inWaitConditionHandle
is returned. For more information, see Functions.Use the Fn::Sub function to substitute the variable in an input string with the value that you specify. In the following code snippet, ${CurlCli} in UserData of
EcsInstanceGroup
is substituted with CurlCli. For more information, see Functions.Use ALIYUN::ROS::WaitCondition and ALIYUN::ROS::WaitConditionHandle to control data initialization in EcsInstanceGroup.
Create the ALIYUN::ROS::WaitCondition resource that is used to wait for a signal.
Create the ALIYUN::ROS::WaitConditionHandle resource that is used to receive a signal.
Execute the scripts that you specify in UserData of EcsInstanceGroup and send signals of the execution process. In the following code snippet, the scripts for data initialization are specified in UserData of
EcsInstanceGroup
and are executed. When the execution of the scripts is successful, ROS calls backWaitConditionHandle
and failsWaitCondition
.
Resources:
WaitCondition:
Type: ALIYUN::ROS::WaitCondition
Properties:
Count: 1
Handle:
Ref: WaitConditionHandle
Timeout: 300
WaitConditionHandle:
Type: ALIYUN::ROS::WaitConditionHandle
EcsInstanceGroup:
Type: ALIYUN::ECS::InstanceGroup
Properties:
InstanceChargeType:
Ref: PayType
PeriodUnit:
Ref: PayPeriodUnit
Period:
Ref: PayPeriod
IoOptimized: optimized
SystemDiskCategory:
Ref: SystemDiskCategory
SystemDiskSize:
Ref: SystemDiskSize
DiskMappings:
- Category:
Ref: DataDiskCategory
Size:
Ref: DataDiskSize
VpcId:
Ref: Vpc
SecurityGroupId:
Ref: EcsSecurityGroup
VSwitchId:
Ref: VSwitch
MaxAmount: 2
ImageId: centos_7
InstanceType:
Ref: EcsInstanceType
Password:
Ref: InstancePassword
AllocatePublicIP: false
UserData:
Fn::Sub:
- |
#!/bin/bash
# Attach the disk to the /disk1 directory.
cat >> /root/InitDataDisk.sh << EOF
#!/bin/bash
echo "p
n
p
w
" | fdisk -u /dev/vdb
EOF
/bin/bash /root/InitDataDisk.sh
rm -f /root/InitDataDisk.sh
rm -f InitDataDisk.sh
mkfs -t ext4 /dev/vdb1
cp /etc/fstab /etc/fstab.bak
mkdir /disk1
echo `blkid /dev/vdb1 | awk '{print $2}' | sed 's/\\\"//g'` /disk1 ext4 defaults 0 0 >> /etc/fstab
mount -a
# Configure an installation script.
yum install -y nginx
# Configure a startup script.
systemctl start nginx.service
# When the execution of the scripts is successful, ROS calls back WaitConditionHandle and fails WaitCondition.
${CurlCli} -d "{\"Data\" : \"Success\", \"status\" : \"SUCCESS\"}"
- CurlCli:
Fn::GetAtt:
- WaitConditionHandle
- CurlCli
Define EcsInstanceGroup, Slb, and SlbBackendServerAttachment
Define the following resources in the template: EcsInstanceGroup
, Slb
, and SlbBackendServerAttachment
.
Use
SlbBackendServerAttachment
to attach the ECS instance group to the CLB instance. For more information, see ALIYUN::SLB::BackendServerAttachment.The ALIYUN::SLB::BackendServerAttachment resource type is subject to the following rules: If you leave
BackendServerWeightList
empty, the weight value of each ECS instance contained in the instances (backend servers) that is specified byBackendServerList
is 100. If the number of the weight values specified byBackendServerWeightList
is less than the number of the instances specified byBackendServerList
, the excessive ECS instances are assigned the last weight value.Use the DependsOn property to specify that a resource is created only after the dependent resource is created. When you add a DependsOn property to a resource, the resource is created only after the resource that is specified in the DependsOn property is created. For more information, see DependsOn.
Use the Fn::GetAtt function to return the property value of a resource. In the following code snippet, the value of
InstanceIds
inEcsInstanceGroup
is returned. For more information, see Functions.
Resources:
EcsInstanceGroup:
Type: ALIYUN::ECS::InstanceGroup
Properties:
InstanceChargeType:
Ref: PayType
PeriodUnit:
Ref: PayPeriodUnit
Period:
Ref: PayPeriod
IoOptimized: optimized
SystemDiskCategory:
Ref: SystemDiskCategory
SystemDiskSize:
Ref: SystemDiskSize
DiskMappings:
- Category:
Ref: DataDiskCategory
Size:
Ref: DataDiskSize
VpcId:
Ref: Vpc
SecurityGroupId:
Ref: EcsSecurityGroup
VSwitchId:
Ref: VSwitch
MaxAmount: 2
ImageId: centos_7
InstanceType:
Ref: EcsInstanceType
Password:
Ref: InstancePassword
AllocatePublicIP: false
Slb:
Type: ALIYUN::SLB::LoadBalancer
Properties:
VpcId:
Ref: Vpc
VSwitchId:
Ref: VSwitch
LoadBalancerName:
Fn::Sub: slb-${ALIYUN::StackName}
PayType:
Ref: PayType
PricingCycle:
Ref: PayPeriodUnit
Duration:
Ref: PayPeriod
AddressType: intranet
LoadBalancerSpec:
Ref: LoadBalancerSpec
AutoPay: true
SlbBackendServerAttachment:
DependsOn:
- EcsInstanceGroup
- Slb
Type: ALIYUN::SLB::BackendServerAttachment
Properties:
BackendServerList:
Fn::GetAtt:
- EcsInstanceGroup
- InstanceIds
LoadBalancerId:
Ref: Slb
BackendServerWeightList:
- 100
- 50
Complete sample template
ROSTemplateFormatVersion: '2015-09-01'
Description:
en: Create new VPC and vSWitch, create one CLB, two ECS instances, and bind all ECS instances to the CLB.
Parameters:
ZoneId:
Type: String
AssociationProperty: ALIYUN::ECS::Instance::ZoneId
Label:
en: vSwitch Availability Zone
VpcCidrBlock:
Default: 192.168.0.0/16
Label:
en: VPC CIDR Block
Type: String
Description:
en: New proprietary network IP address segment range, recommended use of the following IP address segments<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>
VSwitchCidrBlock:
Default: 192.168.0.0/24
Type: String
Description:
en: Must be a sub-network segment of the proprietary network and is not occupied by other vSwitches.
Label:
en: vSwitch CIDR Block
EcsInstanceType:
Type: String
Label:
en: Instance Type
AssociationProperty: ALIYUN::ECS::Instance::InstanceType
AssociationPropertyMetadata:
ZoneId: ${ZoneId}
InstanceChargeType: ${InstanceChargeType}
SystemDiskCategory:
Type: String
Description:
en: '<font color=''blue''><b>Optional values:</b></font><br>[cloud_efficiency: <font color=''green''>Efficient Cloud Disk</font>]<br>[cloud_ssd: <font color=''green''>SSD Cloud Disk</font>]<br>[cloud_essd: <font color=''green''>ESSD Cloud Disk</font>]<br>[cloud: <font color=''green''>Cloud Disk</font>]<br>[ephemeral_ssd: <font color=''green''>Local SSD Cloud Disk</font>]'
AssociationProperty: ALIYUN::ECS::Disk::SystemDiskCategory
AssociationPropertyMetadata:
ZoneId: ${ZoneId}
InstanceType: ${EcsInstanceType}
Label:
en: System Disk Type
SystemDiskSize:
Default: 40
Type: Number
Label:
en: System Disk Space
DataDiskCategory:
AssociationProperty: ALIYUN::ECS::Disk::DataDiskCategory
AssociationPropertyMetadata:
ZoneId: ${ZoneId}
InstanceType: ${EcsInstanceType}
Type: String
Description:
en: '<font color=''blue''><b>Optional values:</b></font><br>[cloud_efficiency: <font color=''green''>Efficient Cloud Disk</font>]<br>[cloud_ssd: <font color=''green''>SSD Cloud Disk</font>]<br>[cloud_essd: <font color=''green''>ESSD Cloud Disk</font>]<br>[cloud: <font color=''green''>Cloud Disk</font>]'
Label:
en: Data Disk Type
DataDiskSize:
Default: 100
MaxValue: 32768
MinValue: 20
Label:
en: Data Disk Space
Type: Number
InstancePassword:
NoEcho: true
Type: String
AllowedPattern: '[0-9A-Za-z\_\-\&:;''<>,=%`~!@#\(\)\$\^\*\+\|\{\}\[\]\.\?\/]+$'
Label:
en: Instance Password
ConstraintDescription:
en: Length 8~30, must contain three(Capital letters, lowercase letters, numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol in).
MinLength: 8
MaxLength: 30
AssociationProperty: ALIYUN::ECS::Instance::Password
PayType:
Type: String
Label:
en: ECS Instance Charge Type
Default: PostPaid
AllowedValues:
- PostPaid
- PrePaid
AssociationProperty: ChargeType
AssociationPropertyMetadata:
LocaleKey: InstanceChargeType
PayPeriodUnit:
Type: String
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>
</b></font>
Label:
en: Pay Period Unit
Default: Month
AllowedValues:
- Month
- Year
AssociationProperty: PayPeriodUnit
AssociationPropertyMetadata:
Visible:
Condition:
Fn::Not:
Fn::Equals:
- ${PayType}
- PostPaid
PayPeriod:
Type: Number
Label:
en: Period
Default: 1
AllowedValues:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
AssociationProperty: PayPeriod
AssociationPropertyMetadata:
Visible:
Condition:
Fn::Not:
Fn::Equals:
- ${PayType}
- PostPaid
LoadBalancerSpec:
Type: String
AssociationProperty: ALIYUN::SLB::Instance::InstanceType
Label:
en: LoadBalancer Specifications
AssociationPropertyMetadata:
ZoneId: ${ZoneId}
Bandwidth:
Description:
en: 'Value range: [0, 1000], Unit: Mbps.'
Default: 10
MaxValue: 1000
Label:
en: CLB Elastic IP Bandwidth
MinValue: 1
Type: Number
Resources:
Vpc:
Type: ALIYUN::ECS::VPC
Properties:
CidrBlock:
Ref: VpcCidrBlock
VpcName:
Ref: ALIYUN::StackName
VSwitch:
Type: ALIYUN::ECS::VSwitch
Properties:
VSwitchName:
Ref: ALIYUN::StackName
VpcId:
Ref: Vpc
ZoneId:
Ref: ZoneId
CidrBlock:
Ref: VSwitchCidrBlock
EcsSecurityGroup:
Type: ALIYUN::ECS::SecurityGroup
Properties:
SecurityGroupName:
Ref: ALIYUN::StackName
VpcId:
Ref: Vpc
SecurityGroupIngress:
- PortRange: 80/80
Priority: 1
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
NicType: internet
SecurityGroupEgress:
- PortRange: '-1/-1'
Priority: 1
IpProtocol: all
DestCidrIp: 0.0.0.0/0
NicType: internet
- PortRange: '-1/-1'
Priority: 1
IpProtocol: all
DestCidrIp: 0.0.0.0/0
NicType: intranet
WaitCondition:
Type: ALIYUN::ROS::WaitCondition
Properties:
Count: 1
Handle:
Ref: WaitConditionHandle
Timeout: 300
WaitConditionHandle:
Type: ALIYUN::ROS::WaitConditionHandle
EcsInstanceGroup:
Type: ALIYUN::ECS::InstanceGroup
Properties:
InstanceChargeType:
Ref: PayType
PeriodUnit:
Ref: PayPeriodUnit
Period:
Ref: PayPeriod
IoOptimized: optimized
SystemDiskCategory:
Ref: SystemDiskCategory
SystemDiskSize:
Ref: SystemDiskSize
DiskMappings:
- Category:
Ref: DataDiskCategory
Size:
Ref: DataDiskSize
VpcId:
Ref: Vpc
SecurityGroupId:
Ref: EcsSecurityGroup
VSwitchId:
Ref: VSwitch
MaxAmount: 2
ImageId: centos_7
InstanceType:
Ref: EcsInstanceType
Password:
Ref: InstancePassword
AllocatePublicIP: false
UserData:
Fn::Sub:
- |
#!/bin/bash
# Attach the disk to the /disk1 directory.
cat >> /root/InitDataDisk.sh << EOF
#!/bin/bash
echo "p
n
p
w
" | fdisk -u /dev/vdb
EOF
/bin/bash /root/InitDataDisk.sh
rm -f /root/InitDataDisk.sh
rm -f InitDataDisk.sh
mkfs -t ext4 /dev/vdb1
cp /etc/fstab /etc/fstab.bak
mkdir /disk1
echo `blkid /dev/vdb1 | awk '{print $2}' | sed 's/\\\"//g'` /disk1 ext4 defaults 0 0 >> /etc/fstab
mount -a
# Configure an installation script.
yum install -y nginx
# Configure a startup script.
systemctl start nginx.service
# When the execution of the scripts is successful, ROS calls back WaitConditionHandle and fails WaitCondition.
${CurlCli} -d "{\"Data\" : \"Success\", \"status\" : \"SUCCESS\"}"
- CurlCli:
Fn::GetAtt:
- WaitConditionHandle
- CurlCli
Slb:
Type: ALIYUN::SLB::LoadBalancer
Properties:
VpcId:
Ref: Vpc
VSwitchId:
Ref: VSwitch
LoadBalancerName:
Fn::Sub: slb-${ALIYUN::StackName}
PayType:
Ref: PayType
PricingCycle:
Ref: PayPeriodUnit
Duration:
Ref: PayPeriod
AddressType: intranet
LoadBalancerSpec:
Ref: LoadBalancerSpec
AutoPay: true
EipSlbAddress:
Type: ALIYUN::VPC::EIP
Properties:
Name:
Ref: ALIYUN::StackName
InternetChargeType: PayByTraffic
Bandwidth:
Ref: Bandwidth
EipSlbAddressAssociation:
Type: ALIYUN::VPC::EIPAssociation
Properties:
InstanceId:
Ref: Slb
AllocationId:
Ref: EipSlbAddress
SlbBackendServerAttachment:
DependsOn:
- EcsInstanceGroup
Type: ALIYUN::SLB::BackendServerAttachment
Properties:
BackendServerList:
Fn::GetAtt:
- EcsInstanceGroup
- InstanceIds
LoadBalancerId:
Ref: Slb
BackendServerWeightList:
- 100
- 100
SlbListener:
DependsOn:
- Slb
Type: ALIYUN::SLB::Listener
Properties:
Persistence:
CookieTimeout: 60
StickySession: 'on'
PersistenceTimeout: 180
XForwardedFor: 'off'
StickySessionType: insert
ListenerPort: 80
Bandwidth: -1
HealthCheck:
HttpCode: http_2xx,http_3xx,http_4xx,http_5xx
HealthCheckType: tcp
UnhealthyThreshold: 3
Timeout: 5
HealthyThreshold: 3
Port: 80
URI: /
Interval: 2
LoadBalancerId:
Ref: Slb
BackendServerPort: 80
Protocol: tcp
Outputs:
Endpoint:
Description:
en: Public IP Addresses.
Value:
Fn::Sub:
- http://${ServerAddress}
- ServerAddress:
Fn::GetAtt:
- EipSlbAddress
- EipAddress
Add parameter groups to a template and display the valid values of a parameter based on a filter condition
In the preceding template, multiple resources are defined and associated. The value of the LoadBalancerSpec
property of the Slb
resource and the values of the InstanceType
and SystemDiskCategory
properties of the EcsInstanceGroup
resource reference the values of specific parameters. Each time you create a stack in a different region, you must modify the template structure and change the property values.
In this case, you can add the Parameters section to improve the flexibility and reusability of the template.
Add parameter groups to a template
You can add the Metadata section to a template to group the parameters that are defined in the Parameters section and define a label for each group.
After you define resources and parameters in a template, you can group parameters by resource or by resource parameter.
The following table lists parameter groups that are added based on the complete sample template. In this example, the parameters are grouped by resource name or resource parameter name.
Parameter group | Resource name | Resource parameter name |
Basic network configurations |
|
|
CLB configurations |
|
|
ECS configurations |
|
|
Display the valid values of a parameter based on a filter condition
If you want to specify a filter condition for a parameter and associate the parameter value with the filter condition chosen in the ROS console, you can specify AssociationProperty and AssociationPropertyMetadata in your template. In this example, the valid values of the ECSInstanceType
parameter are displayed based on the value of ZoneId
and InstanceChargeType
. To specify AssociationProperty and AssociationPropertyMetadata in ECSInstanceType, use ALIYUN::ECS::InstanceGroup to query the value of AssociationProperty that is supported by ECSInstanceType in the documentation of ROS. The following value is queried: ALIYUN::ECS::Instance::InstanceType. Then, query the value of AssociationPropertyMetadata when AssociationProperty is set to ALIYUN::ECS::Instance::InstanceType and when ZoneId and InstanceChargeType are used as filter conditions. For more information about the documentation, see AssociationProperty and AssociationPropertyMetadata.
Complete sample template
ROSTemplateFormatVersion: '2015-09-01'
Description:
en: Create new VPC and vSWitch,, create one CLB, two ECS instances, and bind all ECS instances to the CLB.
Parameters:
ZoneId:
Type: String
AssociationProperty: ALIYUN::ECS::Instance::ZoneId
Label:
en: vSwitch Availability Zone
VpcCidrBlock:
Default: 192.168.0.0/16
Label:
en: VPC CIDR Block
Type: String
Description:
en: New proprietary network IP address segment range, recommended use of the following IP address segments<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>
VSwitchCidrBlock:
Default: 192.168.0.0/24
Type: String
Description:
en: Must be a sub-network segment of the proprietary network and is not occupied by other vSwitches.
Label:
en: vSwitch CIDR Block
EcsInstanceType:
Type: String
Label:
en: Instance Type
AssociationProperty: ALIYUN::ECS::Instance::InstanceType
AssociationPropertyMetadata:
ZoneId: ${ZoneId}
InstanceChargeType: ${InstanceChargeType}
SystemDiskCategory:
Type: String
Description:
en: '<font color=''blue''><b>Optional values:</b></font><br>[cloud_efficiency: <font color=''green''>Efficient Cloud Disk</font>]<br>[cloud_ssd: <font color=''green''>SSD Cloud Disk</font>]<br>[cloud_essd: <font color=''green''>ESSD Cloud Disk</font>]<br>[cloud: <font color=''green''>Cloud Disk</font>]<br>[ephemeral_ssd: <font color=''green''>Local SSD Cloud Disk</font>]'
AssociationProperty: ALIYUN::ECS::Disk::SystemDiskCategory
AssociationPropertyMetadata:
ZoneId: ${ZoneId}
InstanceType: ${EcsInstanceType}
Label:
en: System Disk Type
SystemDiskSize:
Default: 40
Type: Number
Description:
en: 'System disk size, range of values: 40-500, units: GB.'
Label:
en: System Disk Space
DataDiskCategory:
AssociationProperty: ALIYUN::ECS::Disk::DataDiskCategory
AssociationPropertyMetadata:
ZoneId: ${ZoneId}
InstanceType: ${EcsInstanceType}
Type: String
Description:
en: '<font color=''blue''><b>Optional values:</b></font><br>[cloud_efficiency: <font color=''green''>Efficient Cloud Disk</font>]<br>[cloud_ssd: <font color=''green''>SSD Cloud Disk</font>]<br>[cloud_essd: <font color=''green''>ESSD Cloud Disk</font>]<br>[cloud: <font color=''green''>Cloud Disk</font>]'
Label:
en: Data Disk Type
DataDiskSize:
Description:
en: 'ECS Instance disk size, range of values: 20-32768, units: GB.'
Default: 100
MaxValue: 32768
MinValue: 20
Label:
en: Data Disk Space
Type: Number
InstancePassword:
NoEcho: true
Type: String
Description:
en: Server login password, Length 8~30, must contain three(Capital letters, lowercase letters, numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol in).
AllowedPattern: '[0-9A-Za-z\_\-\&:;''<>,=%`~!@#\(\)\$\^\*\+\|\{\}\[\]\.\?\/]+$'
Label:
en: Instance Password
ConstraintDescription:
en: Length 8~30, must contain three(Capital letters, lowercase letters, numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol in).
MinLength: 8
MaxLength: 30
AssociationProperty: ALIYUN::ECS::Instance::Password
PayType:
Type: String
Label:
en: ECS Instance Charge Type
Default: PostPaid
AllowedValues:
- PostPaid
- PrePaid
AssociationProperty: ChargeType
AssociationPropertyMetadata:
LocaleKey: InstanceChargeType
PayPeriodUnit:
Type: String
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>
</b></font>
Label:
en: Pay Period Unit
Default: Month
AllowedValues:
- Month
- Year
AssociationProperty: PayPeriodUnit
AssociationPropertyMetadata:
Visible:
Condition:
Fn::Not:
Fn::Equals:
- ${PayType}
- PostPaid
PayPeriod:
Type: Number
Label:
en: Period
Default: 1
AllowedValues:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
AssociationProperty: PayPeriod
AssociationPropertyMetadata:
Visible:
Condition:
Fn::Not:
Fn::Equals:
- ${PayType}
- PostPaid
LoadBalancerSpec:
Type: String
AssociationProperty: ALIYUN::SLB::Instance::InstanceType
Label:
en: LoadBalancer Specifications
AssociationPropertyMetadata:
ZoneId: ${ZoneId}
Bandwidth:
Description:
en: 'Value range: [0, 1000], Unit: Mbps.'
Default: 10
MaxValue: 1000
Label:
en: CLB Elastic IP Bandwidth
MinValue: 1
Type: Number
Resources:
Vpc:
Type: ALIYUN::ECS::VPC
Properties:
CidrBlock:
Ref: VpcCidrBlock
VpcName:
Ref: ALIYUN::StackName
VSwitch:
Type: ALIYUN::ECS::VSwitch
Properties:
VSwitchName:
Ref: ALIYUN::StackName
VpcId:
Ref: Vpc
ZoneId:
Ref: ZoneId
CidrBlock:
Ref: VSwitchCidrBlock
EcsSecurityGroup:
Type: ALIYUN::ECS::SecurityGroup
Properties:
SecurityGroupName:
Ref: ALIYUN::StackName
VpcId:
Ref: Vpc
SecurityGroupIngress:
- PortRange: 80/80
Priority: 1
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
NicType: internet
SecurityGroupEgress:
- PortRange: '-1/-1'
Priority: 1
IpProtocol: all
DestCidrIp: 0.0.0.0/0
NicType: internet
- PortRange: '-1/-1'
Priority: 1
IpProtocol: all
DestCidrIp: 0.0.0.0/0
NicType: intranet
WaitCondition:
Type: ALIYUN::ROS::WaitCondition
Properties:
Count: 1
Handle:
Ref: WaitConditionHandle
Timeout: 300
WaitConditionHandle:
Type: ALIYUN::ROS::WaitConditionHandle
EcsInstanceGroup:
Type: ALIYUN::ECS::InstanceGroup
Properties:
InstanceChargeType:
Ref: PayType
PeriodUnit:
Ref: PayPeriodUnit
Period:
Ref: PayPeriod
IoOptimized: optimized
SystemDiskCategory:
Ref: SystemDiskCategory
SystemDiskSize:
Ref: SystemDiskSize
DiskMappings:
- Category:
Ref: DataDiskCategory
Size:
Ref: DataDiskSize
VpcId:
Ref: Vpc
SecurityGroupId:
Ref: EcsSecurityGroup
VSwitchId:
Ref: VSwitch
MaxAmount: 2
ImageId: centos_7
InstanceType:
Ref: EcsInstanceType
Password:
Ref: InstancePassword
AllocatePublicIP: false
UserData:
Fn::Sub:
- |
#!/bin/bash
# Attach the disk to the /disk1 directory.
cat >> /root/InitDataDisk.sh << EOF
#!/bin/bash
echo "p
n
p
w
" | fdisk -u /dev/vdb
EOF
/bin/bash /root/InitDataDisk.sh
rm -f /root/InitDataDisk.sh
rm -f InitDataDisk.sh
mkfs -t ext4 /dev/vdb1
cp /etc/fstab /etc/fstab.bak
mkdir /disk1
echo `blkid /dev/vdb1 | awk '{print $2}' | sed 's/\\\"//g'` /disk1 ext4 defaults 0 0 >> /etc/fstab
mount -a
# Configure an installation script.
yum install -y nginx
# Configure a startup script.
systemctl start nginx.service
# When the execution of the scripts is successful, ROS calls back WaitConditionHandle and fails WaitCondition.
${CurlCli} -d "{\"Data\" : \"Success\", \"status\" : \"SUCCESS\"}"
- CurlCli:
Fn::GetAtt:
- WaitConditionHandle
- CurlCli
Slb:
Type: ALIYUN::SLB::LoadBalancer
Properties:
VpcId:
Ref: Vpc
VSwitchId:
Ref: VSwitch
LoadBalancerName:
Fn::Sub: slb-${ALIYUN::StackName}
PayType:
Ref: PayType
PricingCycle:
Ref: PayPeriodUnit
Duration:
Ref: PayPeriod
AddressType: intranet
LoadBalancerSpec:
Ref: LoadBalancerSpec
AutoPay: true
EipSlbAddress:
Type: ALIYUN::VPC::EIP
Properties:
Name:
Ref: ALIYUN::StackName
InternetChargeType: PayByTraffic
Bandwidth:
Ref: Bandwidth
EipSlbAddressAssociation:
Type: ALIYUN::VPC::EIPAssociation
Properties:
InstanceId:
Ref: Slb
AllocationId:
Ref: EipSlbAddress
SlbBackendServerAttachment:
DependsOn:
- EcsInstanceGroup
Type: ALIYUN::SLB::BackendServerAttachment
Properties:
BackendServerList:
Fn::GetAtt:
- EcsInstanceGroup
- InstanceIds
LoadBalancerId:
Ref: Slb
BackendServerWeightList:
- 100
- 50
SlbListener:
DependsOn:
- Slb
Type: ALIYUN::SLB::Listener
Properties:
Persistence:
CookieTimeout: 60
StickySession: 'on'
PersistenceTimeout: 180
XForwardedFor: 'off'
StickySessionType: insert
ListenerPort: 80
Bandwidth: -1
HealthCheck:
HttpCode: http_2xx,http_3xx,http_4xx,http_5xx
HealthCheckType: tcp
UnhealthyThreshold: 3
Timeout: 5
HealthyThreshold: 3
Port: 80
URI: /
Interval: 2
LoadBalancerId:
Ref: Slb
BackendServerPort: 80
Protocol: tcp
Outputs:
Endpoint:
Description:
en: Public IP Addresses
Value:
Fn::Sub:
- http://${ServerAddress}
- ServerAddress:
Fn::GetAtt:
- EipSlbAddress
- EipAddress
Metadata:
ALIYUN::ROS::Interface:
ParameterGroups:
- Parameters:
- ZoneId
- VpcCidrBlock
- VSwitchCidrBlock
Label:
default:
en: Basic Network Configuration
- Parameters:
- PayType
- PayPeriodUnit
- PayPeriod
Label:
default:
en: PayType Configuration
- Parameters:
- EcsInstanceType
- SystemDiskCategory
- SystemDiskSize
- DataDiskCategory
- DataDiskSize
- InstancePassword
Label:
default:
en: Instance Configure
- Parameters:
- LoadBalancerSpec
- Bandwidth
Label:
default:
en: CLB Configure