Template name
The ACS-TAG-ExtendEcsInstanceTagsByInputParams action causes resources associated with an ECS instance, such as disks, images, snapshots, EIPs, and ENIs, to inherit tags from the instance.
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 | Task execution concurrency | 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": [
"oos:GetApplicationGroup"
],
"Resource": "*",
"Effect": "Allow"
},
{
"Action": [
"vpc:ListTagResources",
"vpc:TagResources"
],
"Resource": "*",
"Effect": "Allow"
}
]
}
Details
For more information, see ACS-TAG-ExtendEcsInstanceTagsByInputParams.yml at GitHub.
Template content
FormatVersion: OOS-2019-06-01
Description:
en: Applies tags from an ECS instance to its related resources (disks, images, snapshots, EIPs, and ENIs).
zh-cn: Applies tags from an ECS instance to its related resources (disks, images, snapshots, EIPs, and ENIs).
name-en: ACS-TAG-ExtendEcsInstanceTagsByInputParams
name-zh-cn: Applies tags from an ECS instance to its related resources (disks, images, snapshots, EIPs, and ENIs).
categories:
- tag_manage
Parameters:
regionId:
Label:
en: Region
zh-cn: Region
Type: String
AssociationProperty: RegionId
Default: '{{ ACS::RegionId }}'
targets:
Label:
en: TargetInstance
zh-cn: Target Instances
Type: Json
AssociationProperty: Targets
AssociationPropertyMetadata:
ResourceType: ALIYUN::ECS::Instance
RegionId: regionId
tagKeys:
Label:
en: TagKeys
zh-cn: Tag Keys to Inherit
Type: List
resourceTypes:
Label:
en: ResourceTypes
zh-cn: Resource Types to Inherit Tags
Type: List
AllowedValues:
- disk
- snapshot
- eni
- eip
- image
isUpdate:
Label:
en: IsUpdate
zh-cn: Overwrite Tag Value
Description:
en: Whether to overwrite the tag value if the tag key is the same
zh-cn: Whether to overwrite the tag value if the tag key is the same
Type: Boolean
Default: false
rateControl:
Label:
en: RateControl
zh-cn: Task Concurrency Rate
Type: Json
AssociationProperty: RateControl
Default:
Mode: Concurrency
MaxErrors: 100
Concurrency: 50
OOSAssumeRole:
Label:
en: OOSAssumeRole
zh-cn: OOS RAM Role
Type: String
Default: ''
RamRole: '{{ OOSAssumeRole }}'
Tasks:
- Name: getInstanceTagResources
Description:
en: Queries the ECS instances and their tag information.
zh-cn: Queries the ECS instances and their tag information.
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: Checks whether to extend tags to disks.
zh-cn: Checks whether to extend tags to disks.
Properties:
DefaultTask: isTagSnapshot
Choices:
- When:
Fn::Equals:
- true
- Fn::Jq:
- First
- contains(["disk"])
- '{{resourceTypes}}'
NextTask: tagDisk
- Name: tagDisk
Action: ACS::Template
Description:
en: Updates disk tags based on the ECS instance tags.
zh-cn: Updates disk tags based on the ECS instance tags.
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: Checks whether to extend tags to snapshots.
zh-cn: Checks whether to extend tags to snapshots.
Properties:
DefaultTask: isTagENI
Choices:
- When:
Fn::Equals:
- true
- Fn::Jq:
- First
- contains(["snapshot"])
- '{{resourceTypes}}'
NextTask: tagSnapshot
- Name: tagSnapshot
Action: ACS::Template
Description:
en: Updates snapshot tags based on the ECS instance tags.
zh-cn: Updates snapshot tags based on the ECS instance tags.
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: Checks whether to extend tags to ENIs.
zh-cn: Checks whether to extend tags to ENIs.
Properties:
DefaultTask: isTagEIP
Choices:
- When:
Fn::Equals:
- true
- Fn::Jq:
- First
- contains(["eni"])
- '{{resourceTypes}}'
NextTask: tagENI
- Name: tagENI
Action: ACS::Template
Description:
en: Updates ENI tags based on the ECS instance tags.
zh-cn: Updates ENI tags based on the ECS instance tags.
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: Chooses the next task based on the resource type.
zh-cn: Chooses the next task based on the resource type.
Properties:
DefaultTask: isTagImage
Choices:
- When:
Fn::Equals:
- true
- Fn::Jq:
- First
- contains(["eni"])
- '{{resourceTypes}}'
NextTask: tagEIP
- Name: tagEIP
Action: ACS::Template
Description:
en: Updates EIP tags based on the ECS instance tags.
zh-cn: Updates EIP tags based on the ECS instance tags.
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: Chooses the next task based on the resource type.
zh-cn: Chooses the next task based on the resource type.
Properties:
DefaultTask: ACS::END
Choices:
- When:
Fn::Equals:
- true
- Fn::Jq:
- First
- contains(["image"])
- '{{resourceTypes}}'
NextTask: tagImage
- Name: tagImage
Action: ACS::Template
Description:
en: Updates custom image tags based on the ECS instance tags.
zh-cn: Updates custom image tags based on the ECS instance tags.
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