You can use Resource Orchestration Service (ROS) stack groups to create ECS instances with the same configuration across multiple Alibaba Cloud accounts and regions.
Prerequisites
If you use the self-managed permission model to create a stack group, ensure you have created an administrator account and target accounts. You must also manually create RAM roles in the administrator and target accounts to establish a trust relationship between them. For more information, see Grant self-managed permissions.
If you use the service-managed permission model to create a stack group, ensure you have set up a delegated administrator account. For more information, see Set up a delegated administrator account.
Step 1: Prepare the template
ROSTemplateFormatVersion: '2015-09-01'
Description: Creates One ECS instance
Resources:
DS-InstanceTypes:
Type: DATASOURCE::ECS::RecommendInstanceTypes
Properties:
Cores: 2
Memory: 8
SystemDiskCategory: cloud_essd
Vpc:
Type: ALIYUN::ECS::VPC
Properties:
CidrBlock: 192.168.0.0/16
VSwitch:
Type: ALIYUN::ECS::VSwitch
Properties:
VpcId:
Ref: Vpc
CidrBlock: 192.168.0.0/24
ZoneId:
Fn::Jq:
- First
- .[].ZoneId
- Fn::GetAtt:
- DS-InstanceTypes
- InstanceTypes
SecurityGroup:
Type: ALIYUN::ECS::SecurityGroup
Properties:
VpcId:
Ref: Vpc
Instance:
Type: ALIYUN::ECS::Instance
Properties:
IoOptimized: optimized
PrivateIpAddress: 192.168.0.1
VpcId:
Ref: Vpc
SecurityGroupId:
Ref: SecurityGroup
VSwitchId:
Ref: VSwitch
ImageId: centos
InstanceType:
Fn::Jq:
- First
- .[].InstanceType
- Fn::GetAtt:
- DS-InstanceTypes
- InstanceTypes
SystemDiskCategory: cloud_essd
Outputs:
VpcId:
Value:
Fn::GetAtt:
- Vpc
- VpcId
InstanceId:
Value:
Fn::GetAtt:
- Instance
- InstanceIdTemplate description:
The
Resourcessection defines the resources to be created.The
Outputssection specifies that the IDs of the created VPC and ECS instance are returned after the stack is created.
Step 2: Create a stack group
-
Log on to the ROS console.
-
In the navigation pane on the left, click Stack Groups.
From the region drop-down list in the top navigation bar, select the region for the stack group.
-
On the Stack Groups page, click Create Stack Group.
On the Select Template page, select Enter Template Content for Template Import Method, and paste the YAML template from Step 1: Prepare the template.
On the Configure Parameters page, enter a Stack Group Name and Stack Group Description, and then click Next.
-
In the Configure Stack Group step, set the permission model to Service-managed Permissions or Self-managed Permissions based on your business requirements, and click Next.
For more information about service-managed permissions and self-managed permissions, see the "Permission models" section of the Overview topic.
On the Set Deployment Options page, configure the deployment parameters, and then click Next.
If you use the service-managed permission model, select multiple members from your resource directory as Deployment Destinations and select multiple deployment regions.
Configure other parameters as needed. For more information, see Create a stack group by using the service-managed permission model.
If you use the self-managed permission model, for Deployment Locations, select Deploy Stacks Within Accounts. Then, add the target accounts and select the deployment regions.
Configure other parameters as needed. For more information, see Create a stack group by using the self-managed permission model.
NoteYou can select up to 20 regions.
-
On the Check and Confirm page, verify the stack group information and click Create Stack Group.
Step 3: View the stack group
-
In the left-side navigation pane, click Stack Groups.
-
On the Stack Groups page, find the stack group that you want to view and click the value in the Stack Group Name column.
Click the Instance tab to view the created stack instances and their corresponding stack IDs.
Click a Stack ID. On the Resources tab, you can view all the created resources.
The ECS instance is successfully created when the Resource status is Succeeded.