Resource Orchestration Service (ROS) provides the Count feature that allows you to create multiple resources at a time. This topic describes how to use Count to create multiple Elastic Compute Service (ECS) instances and elastic IP addresses (EIPs) at a time and bind the EIPs to the ECS instances.
Background information
ALIYUN::VPC::EIP is used to apply for EIPs. If you use a template to apply for multiple EIPs at a time, you must specify multiple ALIYUN::VPC::EIP resources in the template. This makes the template long-winded. In this case, you can use Count in the template to efficiently create multiple resources at a time. For more information about Count, see Count. When you use Count to create multiple resources at a time, you can specify the DependsOn property and the ParallelCount parameter to control concurrency during the resource creation.
Step 1: Create a template
You can use Count to create a template and use the template to create the following resources:
One virtual private cloud (VPC)
One vSwitch
One security group
Four pay-as-you-go ECS instances
Four EIPs
The following sections provide the sample code and the description of the template.
Step 2: Create a stack
Log on to the ROS console.
In the left-side navigation pane, click Stacks.
In the top navigation bar, select the region where you want to create a stack from the region drop-down list. For example, you can select China (Hangzhou).
On the Stacks page, click Create Stack and select Use ROS from the drop-down list.
In the Specify Template section of the Select Template step, select Select an Existing Template.
Set the Template Import Method parameter to Enter Template Content, enter the content of the template that you created in Step 1: Create a template, and then click Next.
In the Configure Parameters step, specify the Stack Name parameter and configure parameters in the Configure Template Parameters section.
In the Configure Stack Settings section, follow on-screen instructions to configure the Stack Policy, Rollback on Failure, Timeout Period, Deletion Protection, RAM Role, Tags, and Resource Group parameters. Then, click Next.
If the resources are not created or updated within the time that is specified by the Timeout Period parameter, the system considers the operation failed. Then, the system determines whether to roll back the resources to the state before they are created or updated based on the value of the Rollback on Failure parameter.
In the Compliance Precheck step, complete the compliance precheck and click Next.
NoteThe compliance precheck feature is available only for specific resources. For more information, see Compliance precheck of ROS.
In the Evaluate Rules section, add compliance rules.
You can add compliance rules based on the cloud resources in the ROS template.
Click Evaluate.
You can modify the template content based on the suggestions that are provided to remediate invalid resources to ensure the compliance of the resources.
In the Check and Confirm step, click Create.
Step 3: (Optional) View the resources and template
After the stack is created, you can view the information about the resources and the template that are preprocessed by ROS on the stack details page.
On the stack details page, click the Resources tab to view the information about the resources.
On the stack details page, click the Template tab to view the information about the template.
The following sample code provides an example of the preprocessed template:
ROSTemplateFormatVersion: '2015-09-01' Resources: EipBind[1]: Type: ALIYUN::VPC::EIPAssociation Properties: InstanceId: Fn::Select: - 1 - Fn::GetAtt: - Servers - InstanceIds AllocationId: Ref: Eip[1] Eip[1]: Type: ALIYUN::VPC::EIP Properties: Bandwidth: 5 SecurityGroup: Type: ALIYUN::ECS::SecurityGroup Properties: VpcId: Ref: Vpc SecurityGroupName: test-resource-count Servers: Type: ALIYUN::ECS::InstanceGroup Properties: SystemDiskCategory: Ref: SystemDiskCategory VpcId: Ref: Vpc SecurityGroupId: Ref: SecurityGroup ImageId: centos_7 AllocatePublicIP: false VSwitchId: Ref: VSwitch Password: Ref: Password InstanceType: Ref: InstanceType MaxAmount: Ref: Count Eip[2]: Type: ALIYUN::VPC::EIP Properties: Bandwidth: 5 DependsOn: Eip[0] Eip[0]: Type: ALIYUN::VPC::EIP Properties: Bandwidth: 5 Vpc: Type: ALIYUN::ECS::VPC Properties: VpcName: test-resource-count CidrBlock: 10.0.0.0/8 Eip[3]: Type: ALIYUN::VPC::EIP Properties: Bandwidth: 5 DependsOn: Eip[1] VSwitch: Type: ALIYUN::ECS::VSwitch Properties: VpcId: Ref: Vpc CidrBlock: 10.0.10.0/24 ZoneId: Ref: ZoneId EipBind[3]: Type: ALIYUN::VPC::EIPAssociation Properties: InstanceId: Fn::Select: - 3 - Fn::GetAtt: - Servers - InstanceIds AllocationId: Ref: Eip[3] DependsOn: EipBind[1] EipBind[0]: Type: ALIYUN::VPC::EIPAssociation Properties: InstanceId: Fn::Select: - 0 - Fn::GetAtt: - Servers - InstanceIds AllocationId: Ref: Eip[0] EipBind[2]: Type: ALIYUN::VPC::EIPAssociation Properties: InstanceId: Fn::Select: - 2 - Fn::GetAtt: - Servers - InstanceIds AllocationId: Ref: Eip[2] DependsOn: EipBind[0] Parameters: Count: Default: 4 Type: Number SystemDiskCategory: Type: String ZoneId: Type: String Password: Default: Abc1**** NoEcho: true Type: String InstanceType: Default: ecs.c6.large Type: String ParallelCount: Default: 2 Type: Number Outputs: AllocationIds: Value: - Ref: Eip[0] - Ref: Eip[1] - Ref: Eip[2] - Ref: Eip[3] InstanceIds: Value: Fn::GetAtt: - Servers - InstanceIds EipAddresses: Value: - Fn::GetAtt: - Eip[0] - EipAddress - Fn::GetAtt: - Eip[1] - EipAddress - Fn::GetAtt: - Eip[2] - EipAddress - Fn::GetAtt: - Eip[3] - EipAddress