In Resource Orchestration Service (ROS), you can use the Count feature to create multiple resources at a time.
Background information
ALIYUN::VPC::EIP is used to apply for an elastic IP address (EIP). To apply for multiple EIPs, you must specify multiple ALIYUN::VPC::EIP resources in a template. However, this makes the template verbose. In this case, you can use the Count feature to create multiple resources at a time. For more information about the Count feature, see Count.
The Count feature is used in this topic to create multiple ECS instances and EIPs, and bind the EIPs to the ECS instances. The following resources are created in the examples:
- One VPC
- One VSwitch
- One security group
- Two pay-as-you-go ECS instances
- Two EIPs
Procedure
Result
After the stack is created, you can click the Resources tab on the stack details page to view the resource information after preprocessing.
You can also click the Template tab on the stack details page to view the template information after preprocessing.
{
"ROSTemplateFormatVersion": "2015-09-01",
"Parameters": {
"Count": {
"Default": 2,
"Type": "Number"
},
"Password": {
"Default": "Abc12345",
"NoEcho": true,
"Type": "String"
},
"InstanceType": {
"Default": "ecs.c6.large",
"Type": "String"
},
"ZoneId": {
"Type": "String"
}
},
"Resources": {
"Vpc": {
"Type": "ALIYUN::ECS::VPC",
"Properties": {
"VpcName": "test-resource-count",
"CidrBlock": "10.0.0.0/8"
}
},
"VSwitch": {
"Type": "ALIYUN::ECS::VSwitch",
"Properties": {
"VpcId": {
"Ref": "Vpc"
},
"CidrBlock": "10.0.10.0/24",
"ZoneId": {
"Ref": "ZoneId"
}
}
},
"SecurityGroup": {
"Type": "ALIYUN::ECS::SecurityGroup",
"Properties": {
"VpcId": {
"Ref": "Vpc"
},
"SecurityGroupName": "test-resource-count"
}
},
"Eip[0]": {
"Type": "ALIYUN::VPC::EIP",
"Properties": {
"Bandwidth": 5
}
},
"Eip[1]": {
"Type": "ALIYUN::VPC::EIP",
"Properties": {
"Bandwidth": 5
}
},
"Servers": {
"Type": "ALIYUN::ECS::InstanceGroup",
"Properties": {
"VpcId": {
"Ref": "Vpc"
},
"MinAmount": {
"Ref": "Count"
},
"SecurityGroupId": {
"Ref": "SecurityGroup"
},
"ImageId": "centos_7",
"AllocatePublicIP": false,
"VSwitchId": {
"Ref": "VSwitch"
},
"Password": {
"Ref": "Password"
},
"InstanceType": {
"Ref": "InstanceType"
},
"MaxAmount": {
"Ref": "Count"
}
}
},
"EipBind[0]": {
"Type": "ALIYUN::VPC::EIPAssociation",
"Properties": {
"InstanceId": {
"Fn::Select": [
0,
{
"Fn::GetAtt": [
"Servers",
"InstanceIds"
]
}
]
},
"AllocationId": {
"Ref": "Eip[0]"
}
}
},
"EipBind[1]": {
"Type": "ALIYUN::VPC::EIPAssociation",
"Properties": {
"InstanceId": {
"Fn::Select": [
1,
{
"Fn::GetAtt": [
"Servers",
"InstanceIds"
]
}
]
},
"AllocationId": {
"Ref": "Eip[1]"
}
}
}
},
"Outputs": {
"AllocationIds": {
"Value": [
{
"Ref": "Eip[0]"
},
{
"Ref": "Eip[1]"
}
]
},
"InstanceIds": {
"Value": {
"Fn::GetAtt": [
"Servers",
"InstanceIds"
]
}
},
"EipAddresses": {
"Value": [
{
"Fn::GetAtt": [
"Eip[0]",
"EipAddress"
]
},
{
"Fn::GetAtt": [
"Eip[1]",
"EipAddress"
]
}
]
}
}
}