ACS-ECS-CloneInstancesAcrossRegion

模板名称

ACS-ECS-CloneInstancesAcrossRegion 跨地域克隆ECS实例

立即执行

模板描述

跨地域克隆ECS实例

模板类型

自动化

所有者

Alibaba Cloud

输入参数

参数名称

描述

类型

是否必填

默认值

约束

instanceIds

ECS实例ID列表

List

regionId

源地域ID

String

最大长度 : 30

最小长度 : 1

targetRegionId

目标地域ID

String

最大长度 : 30

最小长度 : 1

targetZoneId

目标可用区ID

String

最大长度 : 30

最小长度 : 1

targetInstanceType

实例类型

String

字符串校验正则表达式 : ecs.[A-Za-z0-9.-]*

最大长度 : 30

最小长度 : 1

targetSecurityGroupId

安全组ID

String

字符串校验正则表达式 : sg-[A-Za-z0-9]*

最大长度 : 30

最小长度 : 1

targetVSwitchId

交换机ID

String

字符串校验正则表达式 : vsw-[A-Za-z0-9]*

最大长度 : 30

最小长度 : 1

OOSAssumeRole

OOS扮演的RAM角色

String

“”

输出参数

参数名称

描述

类型

instanceIds

List

执行此模板需要的权限策略

{
    "Version": "1",
    "Statement": [
        {
            "Action": [
                "ecs:CopyImage",
                "ecs:CreateImage",
                "ecs:DescribeDisks",
                "ecs:DescribeImages",
                "ecs:DescribeInstances",
                "ecs:RunInstances"
            ],
            "Resource": "*",
            "Effect": "Allow"
        }
    ]
}

详情

ACS-ECS-CloneInstancesAcrossRegion详情

模板内容

FormatVersion: OOS-2019-06-01
Description:
  en: Cross Region copy and run ECS instance by InstanceIds
  zh-cn: 跨地域克隆ECS实例
  title: ACS-ECS-CloneInstancesAcrossRegion
  name-en: ACS-ECS-CloneInstancesAcrossRegion
  name-zh-cn: 跨地域克隆ECS实例
  categories:
    - cross_region
Parameters:
  instanceIds:
    Label:
      en: InstanceIds
      zh-cn: ECS实例ID列表
    Type: List
  regionId:
    Label:
      en: RegionId
      zh-cn: 源地域ID
    Type: String
    MinLength: 1
    MaxLength: 30
  targetRegionId:
    Label:
      en: TargetRegionId
      zh-cn: 目标地域ID
    Type: String
    MinLength: 1
    MaxLength: 30
  targetZoneId:
    Label:
      en: TargetZoneId
      zh-cn: 目标可用区ID
    Type: String
    MinLength: 1
    MaxLength: 30
  targetInstanceType:
    Label:
      en: TargetInstanceType
      zh-cn: 实例类型
    Type: String
    AllowedPattern: 'ecs\.[A-Za-z0-9\.\-]*'
    MinLength: 1
    MaxLength: 30
  targetSecurityGroupId:
    Label:
      en: TargetSecurityGroupId
      zh-cn: 安全组ID
    Type: String
    AllowedPattern: 'sg-[A-Za-z0-9]*'
    MinLength: 1
    MaxLength: 30
  targetVSwitchId:
    Label:
      en: TargetVSwitchId
      zh-cn: 交换机ID
    Type: String
    AllowedPattern: 'vsw-[A-Za-z0-9]*'
    MinLength: 1
    MaxLength: 30
  OOSAssumeRole:
    Label:
      en: OOSAssumeRole
      zh-cn: OOS扮演的RAM角色
    Type: String
    Default: ''
RamRole: '{{ OOSAssumeRole }}'
Tasks:
  - Name: queryDisks
    Action: ACS::ExecuteAPI
    Description:
      en: Views disk info of the ECS instance
      zh-cn: 查看实例的磁盘信息
    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: 创建镜像
    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: 等待镜像创建成功
    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: 复制镜像
    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: 等待镜像复制成功
    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: 创建实例
    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: 等待实例创建成功
    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: 设置参数
            en: Configure Parameters
      - Parameters:
          - regionId
          - instanceIds
        Label:
          default:
            zh-cn: 选择实例
            en: Select Ecs Instances
      - Parameters:
          - OOSAssumeRole
        Label:
          default:
            zh-cn: 高级选项
            en: Control Options