ACS-ECS-ApproveROSCreateInstances

模板名称

ACS-ECS-ApproveROSCreateInstances 审批通过ROS创建ECS

立即执行

模板描述

审批通过ROS创建ECS

模板类型

自动化

所有者

Alibaba Cloud

输入参数

参数名称

描述

类型

是否必填

默认值

约束

imageId

将创建实例的镜像ID

String

instanceType

将创建实例的规格

String

zoneId

将创建交换机的目标可用区ID

String

webHookUrl

钉钉群助手的webhook地址

String

atMobiles

审批通知中被@的群成员的钉钉手机号

List

approvers

可以审批任务的用户

List

instancesCount

将创建实例的数量

Number

regionId

地域ID

String

{{ ACS::RegionId }}

atAll

当群助手向钉钉群中发送审批通知时是否@所有人

String

false

minRequiredApprovals

最低需要通过审批的数量

Number

1

OOSAssumeRole

OOS扮演的RAM角色

String

“”

输出参数

参数名称

描述

类型

instanceIds

List

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

{
    "Version": "1",
    "Statement": [
        {
            "Action": [
                "ros:CreateStack",
                "ros:DeleteStack",
                "ros:GetStack"
            ],
            "Resource": "*",
            "Effect": "Allow"
        }
    ]
}

详情

ACS-ECS-ApproveROSCreateInstances详情

模板内容

FormatVersion: OOS-2019-06-01
Description:
  en: Create ECS instances by ROS with approval
  zh-cn: 审批通过ROS创建ECS
  name-en: ACS-ECS-ApproveROSCreateInstances
  name-zh-cn: 审批通过ROS创建ECS
  categories:
    - cost_manage
Parameters:
  regionId:
    Type: String
    Label:
      en: RegionId
      zh-cn: 地域ID
    AssociationProperty: RegionId
    Default: '{{ ACS::RegionId }}'
  imageId:
    Label:
      en: ImageId
      zh-cn: 将创建实例的镜像ID
    Type: String
    AssociationProperty: 'ALIYUN::ECS::Image::ImageId'
    AssociationPropertyMetadata:
      RegionId: regionId
  instanceType:
    Label:
      en: InstanceType
      zh-cn: 将创建实例的规格
    Type: String
    AssociationProperty: 'ALIYUN::ECS::Instance::InstanceType'
  zoneId:
    Label:
      en: ZoneId
      zh-cn: 将创建交换机的目标可用区ID
    AssociationProperty: 'ALIYUN::ECS::Instance::ZoneId'
    Type: String
    AssociationPropertyMetadata:
      RegionId: regionId
  webHookUrl:
    Label:
      en: WebHookUrl
      zh-cn: 钉钉群助手的webhook地址
    Description:
      en: >-
        e.g.https://oapi.dingtalk.com/robot/send?access_token=1234zxcvaksdq31414,acquiring DingTalk webhook please refer to second appendix in https://help.aliyun.com/document_detail/144679.html.
      zh-cn: >-
        形如https://oapi.dingtalk.com/robot/send?access_token=1234zxcvaksdq31414,具体钉钉WebHook获取请参考https://help.aliyun.com/document_detail/144679.html#h2--2-webhook-5。
    Type: String
  atMobiles:
    Label:
      en: AtMobiles
      zh-cn: 审批通知中被@的群成员的钉钉手机号
    Type: List
  atAll:
    Label:
      en: AtAll
      zh-cn: 当群助手向钉钉群中发送审批通知时是否@所有人
    Type: String
    Default: 'false'
  approvers:
    Label:
      en: Approvers
      zh-cn: 可以审批任务的用户
    Description:
      en: the name to fill is the front part of @ in the RAM user name,if  RAM user is user001@companyAlias.onaliyun.com, then fill  user001  in list.
      zh-cn: 用户名是RAM子用户名称中@前面的部分,比如RAM子用户为user001@companyAlias.onaliyun.com,那么列表中填写user001即可
    Type: List
    AssociationProperty: ALIYUN::RAM::User
  minRequiredApprovals:
    Label:
      en: MinRequiredApprovals
      zh-cn: 最低需要通过审批的数量
    Type: Number
    Default: 1
  instancesCount:
    Label:
      en: InstancesCount
      zh-cn: 将创建实例的数量
    Type: Number
  OOSAssumeRole:
    Label:
      en: OOSAssumeRole
      zh-cn: OOS扮演的RAM角色
    Type: String
    Default: ''
RamRole: '{{ OOSAssumeRole }}'
Tasks:
  - Name: approveCreateInstances
    Action: 'ACS::Approve'
    Description:
      en: Approve task creating ECS instances
      zh-cn: 审批后批量创建ECS实例
    Properties:
      Approvers: '{{approvers}}'
      MinRequiredApprovals: '{{minRequiredApprovals}}'
      NotifyType: WebHook
      WebHook:
        URI: '{{webhookUrl}}'
        Headers:
          Content-Type: application/json
        Content:
          msgtype: text
          text:
            content: >-
              Notify: Please approve the task execution to create ECS instance sent by
              {{ACS::RegionId}} oos {{ACS::ExecutionId}}.
          at:
            atMobiles: '{{atMobiles}}'
            isAtAll: '{{atAll}}'

  - Name: createStack
    Action: 'ACS::ExecuteAPI'
    Description:
      en: Create a resource stack
      zh-cn: 创建资源栈
    Properties:
      Service: ROS
      API: CreateStack
      Parameters:
        RegionId: '{{ regionId  }}'
        StackName: 'OOS-{{ACS::ExecutionId}}'
        TimeoutInMinutes: 10
        DisableRollback: false
        Parameters:
          - ParameterKey: instanceType
            ParameterValue: '{{ instanceType }}'
          - ParameterKey: zoneId
            ParameterValue: '{{ zoneId }}'
          - ParameterKey: regionId
            ParameterValue: '{{ regionId  }}'
          - ParameterKey: imageId
            ParameterValue: '{{imageId}}'
          - ParameterKey: executionId
            ParameterValue: '{{ ACS::ExecutionId }}'
          - ParameterKey: instancesCount
            ParameterValue: '{{ instancesCount }}'
        TemplateBody: |
            {
              "Description": "Create VPC ECS instance",
              "Parameters": {
                "imageId": {
                  "Type": "String"
                },
                "instanceType": {
                  "Type": "String"
                },
                "executionId": {
                  "Type": "String"
                },
                "instancesCount": {
                  "Type": "String"
                },
                "zoneId": {
                  "Type": "String"
                },
                "regionId": {
                  "Type": "String"
                },
                "resourcePrefix": {
                  "Type": "String",
                  "Default": "oos-generated"
                }
              },
              "ROSTemplateFormatVersion": "2015-09-01",
              "Outputs": {
                "ecs_instance_id": {
                  "Value": {
                    "Fn::GetAtt": [
                      "ecs",
                      "InstanceIds"
                    ]
                  }
                }
              },
              "Resources": {
                "vswitch": {
                  "Type": "ALIYUN::ECS::VSwitch",
                  "Properties": {
                    "VpcId": {
                      "Ref": "vpc"
                    },
                    "Description": {
                      "Fn::Join": [
                        " ",
                        [
                          "OOS execution id is",
                          {
                            "Ref": "executionId"
                          }
                        ]
                      ]
                    },
                    "ZoneId": {
                      "Ref": "zoneId"
                    },
                    "CidrBlock": "192.168.0.0/16"
                  }
                },
                "sg": {
                  "Type": "ALIYUN::ECS::SecurityGroup",
                  "Properties": {
                    "Tags": [
                      {
                        "Key": "oos-generated",
                        "Value": {
                          "Ref": "executionId"
                        }
                      },
                      {
                        "Key": "region",
                        "Value": {
                          "Ref": "regionId"
                        }
                      }
                    ],
                    "VpcId": {
                      "Ref": "vpc"
                    },
                    "SecurityGroupName": {
                      "Fn::Join": [
                        "-",
                        [
                          {
                            "Ref": "resourcePrefix"
                          },
                          "sg"
                        ]
                      ]
                    },
                    "SecurityGroupEgress": [
                      {
                        "PortRange": "-1/-1",
                        "Priority": 1,
                        "IpProtocol": "all",
                        "DestCidrIp": "0.0.0.0/0",
                        "NicType": "intranet"
                      }
                    ]
                  }
                },
                "vpc": {
                  "Type": "ALIYUN::ECS::VPC",
                  "Properties": {
                    "CidrBlock": "192.168.0.0/16",
                    "Description": {
                      "Fn::Join": [
                        " ",
                        [
                          "OOS execution id is",
                          {
                            "Ref": "executionId"
                          }
                        ]
                      ]
                    },
                    "VpcName": {
                      "Fn::Join": [
                        "-",
                        [
                          {
                            "Ref": "resourcePrefix"
                          },
                          "vpc"
                        ]
                      ]
                    }
                  }
                },
                "ecs": {
                  "Type": "ALIYUN::ECS::InstanceGroup",
                  "Properties": {
                    "ImageId": {
                      "Ref": "imageId"
                    },
                    "SecurityGroupId": {
                      "Ref": "sg"
                    },
                    "VpcId": {
                      "Ref": "vpc"
                    },
                    "VSwitchId": {
                      "Ref": "vswitch"
                    },
                    "InstanceType": {
                      "Ref": "instanceType"
                    },
                    "MinAmount": {
                      "Ref": "instancesCount"
                    },
                    "MaxAmount": {
                      "Ref": "instancesCount"
                    },
                    "Tags": [
                      {
                        "Key": "oos-generated",
                        "Value": {
                          "Ref": "executionId"
                        }
                      },
                      {
                        "Key": "region",
                        "Value": {
                          "Ref": "regionId"
                        }
                      }
                    ]
                  }
                }
              },
              "Metadata": {
                "ALIYUN::ROS::Interface": {
                  "TemplateTags": [
                    "acs:integrate:oos:ecs_approve_ros_create_instances"
                  ]
                }
              }
            }
    Outputs:
      StackId:
        Type: String
        ValueSelector: StackId

  - Name: untilStackReady
    OnSuccess: ACS::END
    OnError: queryStackStatusReason
    Action: 'ACS::WaitFor'
    Description:
      en: Wait for the stack status CREATE_COMPLETE
      zh-cn: 等待资源栈至创建成功状态
    Properties:
      Service: ROS
      API: GetStack
      Parameters:
        RegionId: '{{ regionId  }}'
        StackId: '{{createStack.StackId}}'
      DesiredValues:
        - CREATE_COMPLETE
      StopRetryValues:
        - CREATE_FAILED
        - CHECK_FAILED
        - ROLLBACK_FAILED
        - ROLLBACK_COMPLETE
        - CREATE_ROLLBACK_COMPLETE
      PropertySelector: Status
    Outputs:
      instanceIds:
        Type: String
        ValueSelector: 'Outputs[0].OutputValue'

  - Name: queryStackStatusReason
    Action: ACS::ExecuteAPI
    OnError: deleteStack
    OnSuccess: deleteStack
    Description:
      en: Query the reson of failed created stack
      zh-cn: 查询资源栈未创建成功的原因
    Properties:
      Service: ROS
      API: GetStack
      Parameters:
        RegionId: '{{ regionId  }}'
        StackId: '{{createStack.StackId}}'
    Outputs:
      statusReason:
        Type: String
        ValueSelector: 'StatusReason'

  - Name: deleteStack
    Action: 'ACS::ExecuteApi'
    Description:
      en: Delete the stack
      zh-cn: 删除资源栈
    Properties:
      Service: ROS
      API: DeleteStack
      Parameters:
        RegionId: '{{ regionId  }}'
        StackId: '{{createStack.StackId}}'

Outputs:
  instanceIds:
    Type: List
    Value: '{{ untilStackReady.instanceIds }}'
Metadata:
  ALIYUN::OOS::Interface:
    ParameterGroups:
      - Parameters:
          - webHookUrl
          - atMobiles
          - atAll
          - approvers
          - minRequiredApprovals
        Label:
          default:
            zh-cn: 配置审批
            en: Configure Approval
      - Parameters:
          - regionId
          - zoneId
          - imageId
          - instanceType
          - instancesCount
        Label:
          default:
            zh-cn: 配置实例
            en: Configure ECS Instance
      - Parameters:
          - OOSAssumeRole
        Label:
          default:
            zh-cn: 高级选项
            en: Control Options