This topic describes how to use an Operation Orchestration Service (OOS) custom template to modify a tag value of multiple resources in the same region at a time.

Prerequisites

A tag is added to your Elastic Compute Service (ECS) instances. For more information, see Add a custom tag.

Background information

In this topic, a custom template is created in OOS to modify a tag value of multiple ECS instances at a time. In this example, a tag value of the ECS instances is changed from OldTagValue to NewTagValue. The related tag key-value pair is changed from TagKey:OldTagValue to TagKey:NewTagValue.
Note
  • You can use an OOS custom template to modify a tag value for a maximum of 1,000 resources at a time. If the number of resources is greater than 1,000, you must execute the template multiple times.
  • You can use an OOS custom template to modify the tag values of resources that support tags in the same region. You can modify the related API operations in the template to apply them to various resources. For more information about resources that support tags, see Alibaba Cloud services that support tags. For more information about the resources that are supported by OOS, see List of supported cloud services.

Step 1: Create an OOS custom template

You can perform the following steps to create an OOS custom template that is used to modify a tag value of multiple resources at a time.

  1. Log on to the OOS console.
  2. In the left-side navigation pane, click My Templates.
  3. In the top navigation bar, select a region.
  4. Click Create Template.
  5. In the Basic Information section, enter a name for your template.
  6. Click the JSON tab and write code for the template.

    The following code provides an example:

    {
        "Description": "Modify a tag value of multiple resources at a time",
        "FormatVersion": "OOS-2019-06-01",
        "Parameters": {
            "operateId": {
                "Description": "Define the operation ID",
                "Type": "String",
                "MinLength": 1,
                "MaxLength": 64
            },
            "tagKey": {
                "Description": "Current tag key",
                "Type": "String",
                "MinLength": 1,
                "MaxLength": 64
            },
            "tagValue": {
                "Description": "Current tag value",
                "Type": "String",
                "MinLength": 1,
                "MaxLength": 64
            },
            "newTagValue": {
                "Description": "New tag value",
                "Type": "String",
                "MinLength": 1,
                "MaxLength": 64
            }
        },
        "Tasks": [
            {
                "Name": "DescribeInstances_ECS",
                "Action": "ACS::ExecuteAPI",
                "Description": {
                    "en": "filter ecs instances by tags"
                },
                "Properties": {
                    "Service": "ECS",
                    "API": "DescribeInstances",
                    "AutoPaging": true,
                    "Parameters": {
                        "Tags": [
                            {
                                "Key": "{{ tagKey }}",
                                "Value": "{{ tagValue }}"
                            }
                        ]
                    }
                },
                "Outputs": {
                    "Instances": {
                        "Type": "List",
                        "ValueSelector": "Instances.Instance[].InstanceId"
                    }
                }
            },
            {
                "Name": "TagResources_ECS_Instances",
                "Action": "ACS::ExecuteAPI",
                "Description": {
                    "en": "tag ecs instances"
                },
                "Properties": {
                    "Service": "ECS",
                    "API": "TagResources",
                    "Parameters": {
                        "Tags": [
                            {
                                "Key": "{{ tagKey }}",
                                "Value": "{{ newTagValue }}"
                            }
                        ],
                        "ResourceType": "Instance",
                        "ResourceIds": [
                            "{{ACS::TaskLoopItem}}"
                        ]
                    }
                },
                "Loop": {
                    "MaxErrors": "100%",
                    "Concurrency": 20,
                    "Items": "{{DescribeInstances_ECS.Instances}}"
                }
            }
        ],
        "Outputs": {}
    }
  7. Click Create Template.

Step 2: Execute the custom template

You can perform the following steps to execute the template created in Step 1: Create an OOS custom template to modify a tag value of multiple resources.

  1. In the left-side navigation pane, click My Templates.
  2. Find the template created in Step 1: Create an OOS custom template and click Create Execution in the Actions column.
  3. On the Create page, specify Execution Description and Execution Mode in the Basic Information step. Then, click Next: Parameter Settings.
  4. In the Parameter Settings step, configure the parameters and click Next: OK.

    You must configure the following parameters in this step:

    • operateId: the operation ID, which is used to identify an operation. You can specify this parameter based on your requirements.
    • tagKey: the current tag key. In this example, the current tag key is TagKey.
    • tagValue: the current tag value. In this example, the current tag value is OldTagValue.
    • newTagValue: the new tag value. In this example, the new tag value is NewTagValue.
  5. Click Create.

    The execution details page appears. You can view the execution results on this page.

    Note If the execution fails, you can check logs for the failure cause and make adjustments.