Template name
ACS-ECS-CloneInstancesAcrossRegion
Template description
Clones Elastic Compute Service (ECS) instances across regions.
Template type
Automated
Owner
Alibaba Cloud
Input parameters
Parameter | Description | Type | Required | Default value | Limit |
instanceIds | The IDs of ECS instances to be cloned. | List | Yes | ||
regionId | The ID of the region from which the ECS instances are cloned. | String | Yes | The value must be 1 to 30 characters in length.
| |
targetRegionId | The ID of the region to which the ECS instances are cloned. | String | Yes | The value must be 1 to 30 characters in length.
| |
targetZoneId | The ID of the zone to which the ECS instances are cloned. | String | Yes | The value must be 1 to 30 characters in length.
| |
targetInstanceType | The instance type of the ECS instance. | String | Yes | Regular expression for string verification: ecs.[A-Za-z0-9.-]*. The value must be 1 to 30 characters in length.
| |
targetSecurityGroupId | The security group ID. | String | Yes | Regular expression for string verification: sg-[A-Za-z0-9]*. The value must be 1 to 30 characters in length.
| |
targetVSwitchId | The vSwitch ID. | String | Yes | Regular expression for string verification: vsw-[A-Za-z0-9]*. The value must be 1 to 30 characters in length.
| |
OOSAssumeRole | The Resource Access Management (RAM) role that is assumed by CloudOps Orchestration Service (OOS). | String | No | "" |
Output parameters
Parameter | Description | Type |
instanceIds | List |
Permission policy that is required to execute the template
{
"Version": "1",
"Statement": [
{
"Action": [
"ecs:CopyImage",
"ecs:CreateImage",
"ecs:DescribeDisks",
"ecs:DescribeImages",
"ecs:DescribeInstances",
"ecs:RunInstances"
],
"Resource": "*",
"Effect": "Allow"
}
]
}
References
For more information, see ACS-ECS-CloneInstancesAcrossRegion.yml at GitHub.
Template content
FormatVersion: OOS-2019-06-01
Description:
en: Cross Region copy and run ECS instance by InstanceIds
zh-cn: the description in Chinese
title: ACS-ECS-CloneInstancesAcrossRegion
name-en: ACS-ECS-CloneInstancesAcrossRegion
name-zh-cn: the description in Chinese
categories:
- cross_region
Parameters:
instanceIds:
Label:
en: InstanceIds
zh-cn: the description in Chinese
Type: List
regionId:
Label:
en: RegionId
zh-cn: the description in Chinese
Type: String
MinLength: 1
MaxLength: 30
targetRegionId:
Label:
en: TargetRegionId
zh-cn: the description in Chinese
Type: String
MinLength: 1
MaxLength: 30
targetZoneId:
Label:
en: TargetZoneId
zh-cn: the description in Chinese
Type: String
MinLength: 1
MaxLength: 30
targetInstanceType:
Label:
en: TargetInstanceType
zh-cn: the description in Chinese
Type: String
AllowedPattern: 'ecs\.[A-Za-z0-9\.\-]*'
MinLength: 1
MaxLength: 30
targetSecurityGroupId:
Label:
en: TargetSecurityGroupId
zh-cn: the description in Chinese
Type: String
AllowedPattern: 'sg-[A-Za-z0-9]*'
MinLength: 1
MaxLength: 30
targetVSwitchId:
Label:
en: TargetVSwitchId
zh-cn: the description in Chinese
Type: String
AllowedPattern: 'vsw-[A-Za-z0-9]*'
MinLength: 1
MaxLength: 30
OOSAssumeRole:
Label:
en: OOSAssumeRole
zh-cn: the description in Chinese
Type: String
Default: ''
RamRole: '{{ OOSAssumeRole }}'
Tasks:
- Name: queryDisks
Action: ACS::ExecuteAPI
Description:
en: Views disk info of the ECS instance
zh-cn: the description in Chinese
Properties:
Service: ECS
API: DescribeDisks
Parameters:
RegionId: '{{ regionId }}'
InstanceId: '{{ ACS::TaskLoopItem }}'
Outputs:
instanceDataDisks:
Type: Json
ValueSelector: '.Disks.Disk|map( select(.Type == "data" )|{"Category":(.Category),"Device": (.Device),"Size":(.Size),"DiskName":(.DiskName),"PerformanceLevel":(.PerformanceLevel)})'
instanceSystemDisk:
Type: Json
ValueSelector: '.Disks.Disk|map( select(.Type == "system" )|{"Category":(.Category),"Device": (.Device),"Size":(.Size),"DiskName":(.DiskName),"PerformanceLevel":(.PerformanceLevel)})[]'
Loop:
Items: '{{ instanceIds }}'
Outputs:
dataDisks:
AggregateType: 'Fn::ListJoin'
AggregateField: instanceDataDisks
systemDisks:
AggregateType: 'Fn::ListJoin'
AggregateField: instanceSystemDisk
- Name: createImage
Action: 'ACS::ExecuteAPI'
Description:
en: Create Image
zh-cn: the description in Chinese
Properties:
Service: ECS
API: CreateImage
Parameters:
RegionId: '{{ regionId }}'
ImageName: 'img-{{ ACS::TaskLoopItem }}-{{ACS::ExecutionId}}'
InstanceId: '{{ ACS::TaskLoopItem }}'
DetectionStrategy: Standard
Loop:
Items: '{{ instanceIds }}'
Outputs:
ImageIds:
AggregateType: 'Fn::ListJoin'
AggregateField: ImageId
Outputs:
ImageId:
ValueSelector: ImageId
Type: String
- Name: untilCreateImageReady
Action: 'ACS::WaitFor'
Description:
en: Wait For created images available
zh-cn: the description in Chinese
Properties:
Service: ECS
API: DescribeImages
Parameters:
RegionId: '{{ regionId }}'
ImageId: '{{ ACS::TaskLoopItem }}'
DesiredValues:
- Available
PropertySelector: 'Images.Image[].Status'
Loop:
Items: '{{ createImage.ImageIds }}'
Retries: 57
- Name: copyImage
Action: 'ACS::ExecuteAPI'
Description:
en: Copy image
zh-cn: the description in Chinese
Properties:
Service: ECS
API: CopyImage
Parameters:
RegionId: '{{ regionId }}'
ImageId: '{{ ACS::TaskLoopItem }}'
DestinationRegionId: '{{ targetRegionId }}'
Loop:
Items: '{{ createImage.ImageIds }}'
Outputs:
ImageIds:
AggregateType: 'Fn::ListJoin'
AggregateField: ImageId
Outputs:
ImageId:
ValueSelector: ImageId
Type: String
- Name: untilCopyImageReady
Action: 'ACS::WaitFor'
Description:
en: Wait for copied images available
zh-cn: the description in Chinese
Properties:
Service: ECS
API: DescribeImages
Parameters:
RegionId: '{{ targetRegionId }}'
ImageId: '{{ ACS::TaskLoopItem }}'
DesiredValues:
- Available
PropertySelector: 'Images.Image[].Status'
Loop:
Items: '{{ copyImage.ImageIds }}'
- Name: runInstances
Action: 'ACS::ExecuteAPI'
Description:
en: run instances
zh-cn: the description in Chinese
Properties:
Service: ECS
API: RunInstances
Parameters:
RegionId: '{{ targetRegionId }}'
ZoneId: '{{ targetZoneId }}'
ImageId:
'Fn::Select':
- '{{ ACS::TaskLoopItem }}'
- '{{ copyImage.ImageIds }}'
DataDisks:
'Fn::Select':
- '{{ ACS::TaskLoopItem }}'
- '{{queryDisks.dataDisks}}'
SystemDiskCategory:
'Fn::Select':
- Category
- 'Fn::Select':
- '{{ ACS::TaskLoopItem }}'
- '{{ queryDisks.systemDisks }}'
SystemDiskSize:
'Fn::Select':
- Size
- 'Fn::Select':
- '{{ ACS::TaskLoopItem }}'
- '{{ queryDisks.systemDisks }}'
SystemDiskDiskName:
'Fn::Select':
- DiskName
- 'Fn::Select':
- '{{ ACS::TaskLoopItem }}'
- '{{ queryDisks.systemDisks }}'
SystemDiskPerformanceLevel:
'Fn::Select':
- PerformanceLevel
- 'Fn::Select':
- '{{ ACS::TaskLoopItem }}'
- '{{ queryDisks.systemDisks }}'
InstanceType: '{{ targetInstanceType }}'
SecurityGroupId: '{{ targetSecurityGroupId }}'
VSwitchId: '{{ targetVSwitchId }}'
Loop:
Items:
'Fn::Jq':
- All
- '.|length|range(.)'
- '{{ instanceIds }}'
Outputs:
instanceIds:
AggregateType: 'Fn::ListJoin'
AggregateField: instanceId
Outputs:
instanceId:
Type: String
ValueSelector: 'InstanceIdSets.InstanceIdSet[]'
- Name: untilInstanceReady
Action: 'ACS::WaitFor'
Description:
en: Wait for instances running
zh-cn: the description in Chinese
Properties:
Service: ECS
API: DescribeInstances
Parameters:
RegionId: '{{ targetRegionId }}'
InstanceIds: '{{ runInstances.instanceIds }}'
DesiredValues:
- Running
PropertySelector: '.Instances.Instance[].Status'
Outputs:
instanceIds:
Value: '{{ runInstances.instanceIds }}'
Type: List
Metadata:
ALIYUN::OOS::Interface:
ParameterGroups:
- Parameters:
- targetRegionId
- targetZoneId
- targetInstanceType
- targetSecurityGroupId
- targetVSwitchId
Label:
default:
zh-cn: the description in Chinese
en: Configure Parameters
- Parameters:
- regionId
- instanceIds
Label:
default:
zh-cn: the description in Chinese
en: Select Ecs Instances
- Parameters:
- OOSAssumeRole
Label:
default:
zh-cn: the description in Chinese
en: Control Options