All Products
Search
Document Center

CloudOps Orchestration Service:ACS-TAG-ExtendEcsInstanceTagsByInputParams

Last Updated:Nov 22, 2024

Template name

ACS-TAG-ExtendEcsInstanceTagsByInputParams

Execute Now

Template description

Applies tags of Elastic Compute Service (ECS) instances to associated resources, such as disks, images, snapshots, elastic IP addresses (EIPs), and elastic network interfaces (ENIs).

Template type

Automated

Owner

Alibaba Cloud

Input parameters

Parameter

Description

Type

Required

Default value

Limit

targets

The destination instances.

Json

Yes

tagKeys

The tag keys to be applied.

List

Yes

resourceTypes

The types of resources to which the tags are applied.

List

Yes

regionId

The region ID.

String

No

{{ ACS::RegionId }}

isUpdate

Specifies whether to overwrite tag values.

Boolean

No

False

rateControl

The rate control settings.

Json

No

{'Mode': 'Concurrency', 'MaxErrors': 100, 'Concurrency': 50}

OOSAssumeRole

The Resource Access Management (RAM) role that is assumed by CloudOps Orchestration Service (OOS).

String

No

""

Output parameters

None

Permission policy that is required to execute the template

{
    "Version": "1",
    "Statement": [
        {
            "Action": [
                "ecs:DescribeDisks",
                "ecs:DescribeImages",
                "ecs:DescribeInstances",
                "ecs:DescribeNetworkInterfaces",
                "ecs:DescribeSnapshots",
                "ecs:TagResources"
            ],
            "Resource": "*",
            "Effect": "Allow"
        },
        {
            "Action": [
                "vpc:ListTagResources",
                "vpc:TagResources"
            ],
            "Resource": "*",
            "Effect": "Allow"
        }
    ]
}

References

For more information, see ACS-TAG-ExtendEcsInstanceTagsByInputParams.yml at GitHub.

Template content

FormatVersion: OOS-2019-06-01
Description:
  en: Ecs instance related resources (Disk, Image, Snapshot, EIP, ENI) inherit the Tags of the Instance
  zh-cn: the description in Chinese
  name-en: ACS-TAG-ExtendEcsInstanceTagsByInputParams
  name-zh-cn: the description in Chinese
Parameters:
  regionId:
    Label:
      en: RegionId
      zh-cn: the description in Chinese
    Type: String
    AssociationProperty: RegionId
    Default: '{{ ACS::RegionId }}'
  targets:
    Label:
      en: TargetInstance
      zh-cn: the description in Chinese
    Type: Json
    AssociationProperty: Targets
    AssociationPropertyMetadata:
      ResourceType: ALIYUN::ECS::Instance
      RegionId: regionId
  tagKeys:
    Label:
      en: TagKeys
      zh-cn: the description in Chinese
    Type: List
  resourceTypes:
    Label:
      en: ResourceTypes
      zh-cn: the description in Chinese
    Type: List
    AllowedValues:
      - disk
      - snapshot
      - eni
      - eip
      - image
  isUpdate:
    Label:
      en: IsUpdate
      zh-cn: the description in Chinese
    Description:
      en: Whether to overwrite the tag value if the tag key is the same
      zh-cn: the description in Chinese
    Type: Boolean
    Default: false
  rateControl:
    Label:
      en: RateControl
      zh-cn: the description in Chinese
    Type: Json
    AssociationProperty: RateControl
    Default:
      Mode: Concurrency
      MaxErrors: 100
      Concurrency: 50
  OOSAssumeRole:
    Label:
      en: OOSAssumeRole
      zh-cn: the description in Chinese
    Type: String
    Default: ''
RamRole: '{{ OOSAssumeRole }}'
Tasks:
  - Name: getInstanceTagResources
    Description:
      en: Query the ECS instances
      zh-cn: the description in Chinese
    Action: ACS::SelectTargets
    Properties:
      ResourceType: ALIYUN::ECS::Instance
      RegionId: '{{ regionId }}'
      Filters:
        - '{{ targets }}'
    Outputs:
      desData:
        Type: List
        ValueSelector: '.Instances.Instance[] | {"Tags": .Tags.Tag | map(select( .TagKey | test("^(?!acs).*"))) | map(select(.TagKey as $tagKey | {{tagKeys}} | index($tagKey) >=0)) , "InstanceId": .InstanceId}?'
  - Name: isTagDisk
    Action: ACS::Choice
    Description:
      en: Disk Extend  Tags
      zh-cn: the description in Chinese
    Properties:
      DefaultTask: isTagSnapshot
      Choices:
        - When:
            Fn::Equals:
              - true
              - Fn::Jq:
                  - First
                  - contains(["disk"])
                  - '{{resourceTypes}}'
          NextTask: tagDisk
  - Name: tagDisk
    Action: ACS::Template
    Description:
      en: Update disk tags by ecs instance tags
      zh-cn: the description in Chinese
    OnSuccess: isTagSnapshot
    Properties:
      TemplateName: ACS::ECS::UpdateDiskTagsByEcsInstanceTags
      Parameters:
        regionId: '{{ regionId }}'
        instanceId:
          Fn::Jq:
            - First
            - .InstanceId
            - '{{ACS::TaskLoopItem}}'
        tagKeys: '{{tagKeys}}'
        isUpdate: '{{isUpdate}}'
    Loop:
      RateControl: '{{rateControl}}'
      Items: '{{getInstanceTagResources.desData}}'
      Outputs:
        tagResult:
          AggregateType: Fn::ListJoin
          AggregateField: reqResult
  - Name: isTagSnapshot
    Action: ACS::Choice
    Description:
      en: Snapshot Extend  Tags
      zh-cn: the description in Chinese
    Properties:
      DefaultTask: isTagENI
      Choices:
        - When:
            Fn::Equals:
              - true
              - Fn::Jq:
                  - First
                  - contains(["snapshot"])
                  - '{{resourceTypes}}'
          NextTask: tagSnapshot
  - Name: tagSnapshot
    Action: ACS::Template
    Description:
      en: Update snapshot tags by ecs instance tags
      zh-cn: the description in Chinese
    OnSuccess: isTagENI
    Properties:
      TemplateName: ACS::ECS::UpdateSnapshotTagsByEcsInstanceTags
      Parameters:
        regionId: '{{regionId}}'
        instanceId:
          Fn::Jq:
            - First
            - .InstanceId
            - '{{ACS::TaskLoopItem}}'
        tagKeys: '{{tagKeys}}'
        isUpdate: '{{isUpdate}}'
    Loop:
      RateControl: '{{rateControl}}'
      Items: '{{getInstanceTagResources.desData}}'
      Outputs:
        tagResult:
          AggregateType: Fn::ListJoin
          AggregateField: reqResult
  - Name: isTagENI
    Action: ACS::Choice
    Description:
      en: ENI Extend Tags
      zh-cn: the description in Chinese
    Properties:
      DefaultTask: isTagEIP
      Choices:
        - When:
            Fn::Equals:
              - true
              - Fn::Jq:
                  - First
                  - contains(["eni"])
                  - '{{resourceTypes}}'
          NextTask: tagENI
  - Name: tagENI
    Action: ACS::Template
    Description:
      en: Update eni tags by ecs instance tags
      zh-cn: the description in Chinese
    OnSuccess: isTagEIP
    Properties:
      TemplateName: ACS::ECS::UpdateEniTagsByEcsInstanceTags
      Parameters:
        regionId: '{{ regionId }}'
        instanceId:
          Fn::Jq:
            - First
            - .InstanceId
            - '{{ACS::TaskLoopItem}}'
        tagKeys: '{{tagKeys}}'
        isUpdate: '{{isUpdate}}'
    Loop:
      RateControl: '{{rateControl}}'
      Items: '{{getInstanceTagResources.desData}}'
      Outputs:
        tagResult:
          AggregateType: Fn::ListJoin
          AggregateField: reqResult
  - Name: isTagEIP
    Action: ACS::Choice
    Description:
      en: Choose next task by resource type
      zh-cn: the description in Chinese
    Properties:
      DefaultTask: isTagImage
      Choices:
        - When:
            Fn::Equals:
              - true
              - Fn::Jq:
                  - First
                  - contains(["eni"])
                  - '{{resourceTypes}}'
          NextTask: tagEIP
  - Name: tagEIP
    Action: ACS::Template
    Description:
      en: Update eip tags By ecs instance tags
      zh-cn: the description in Chinese
    OnSuccess: isTagImage
    Properties:
      TemplateName: ACS::ECS::UpdateEipTagsByEcsInstanceTags
      Parameters:
        regionId: '{{ regionId }}'
        instanceId:
          Fn::Jq:
            - First
            - .InstanceId
            - '{{ACS::TaskLoopItem}}'
        tagKeys: '{{tagKeys}}'
        isUpdate: '{{isUpdate}}'
    Loop:
      RateControl: '{{rateControl}}'
      Items: '{{getInstanceTagResources.desData}}'
      Outputs:
        tagResult:
          AggregateType: Fn::ListJoin
          AggregateField: reqResult
  - Name: isTagImage
    Action: ACS::Choice
    Description:
      en: Choose next task by resource type
      zh-cn: the description in Chinese
    Properties:
      DefaultTask: ACS::END
      Choices:
        - When:
            Fn::Equals:
              - true
              - Fn::Jq:
                  - First
                  - contains(["image"])
                  - '{{resourceTypes}}'
          NextTask: tagImage
  - Name: tagImage
    Action: ACS::Template
    Description:
      en: Update custom image tags By ecs instance tags
      zh-cn: the description in Chinese
    OnSuccess: ACS::END
    Properties:
      TemplateName: ACS::ECS::UpdateCustomImageTagsByEcsInstanceTags
      Parameters:
        regionId: '{{ regionId }}'
        instanceId:
          Fn::Jq:
            - First
            - .InstanceId
            - '{{ACS::TaskLoopItem}}'
        tagKeys: '{{tagKeys}}'
        isUpdate: '{{isUpdate}}'
    Loop:
      RateControl: '{{rateControl}}'
      Items: '{{getInstanceTagResources.desData}}'
      Outputs:
        tagResult:
          AggregateType: Fn::ListJoin
          AggregateField: reqResult