All Products
Search
Document Center

Elastic Compute Service:use OOS to modify a tag value of multiple resources

最終更新日:Mar 26, 2024

If a tag that has the same tag value is added to hundreds of cloud resources, you can modify the tag value of the cloud resources at a time by using a custom template in CloudOps Orchestration Service (OOS). This topic describes how to modify a tag value of multiple cloud resources at a time in the OOS console.

Prerequisites

A tag is added to cloud resources. For more information, see Create or add a tag.

Background information

In this topic, a custom template is created in the OOS console to modify a tag value of hundreds of ECS instances at a time. In this example, a tag value of the ECS instances is changed from OldTagValue to NewTagValue. The corresponding 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 of up to 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 any resources that support tags in the same region. You can modify the API operations in the template to meet the requirements of various resources. For information about resources that support tags, see Overview. For information about the resources supported by OOS, see List of supported Alibaba Cloud services.

Step 1: Create a template

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

  1. Log on to the CloudOps Orchestration Service (OOS) console.

  2. In the left-side navigation pane, choose Automated Task > Custom Template.

  3. In the top navigation bar, select the region and resource group to which the resource belongs. 地域

  4. On the Custom Template page, click Create Template.

  5. In the Basic Information section, enter a name in the Template Name field.

    You can also click Show More and configure Tag, Resource Group, and Version Description based on your business requirements.

  6. Click the JSON tab and write code in the code editor. Sample code:

    {
        "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 template

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

  1. In the left-side navigation pane, choose Automated Task > Custom Template.

  2. Find the template that you created in Step 1: Create a template and click Create Execution in the Actions column.

  3. On the Create Task page, enter an execution description and select an execution mode in the Basic Information step. Then, click Next Step: Parameter Settings.

  4. In the Parameter Settings step, configure the parameters and click Next Step: OK. The following table describes the parameters.

    Parameter

    Description

    Example

    operateId

    The operation ID, which is used to identify each operation. You can specify a custom operation ID.

    test-user

    tagKey

    The key of the tag whose value you want to modify.

    TagKey

    tagValue

    The tag value that you want to modify.

    OldTagValue

    newTagValue

    The new tag value.

    NewTagValue

  5. Click Create.

    After the template is executed, the execution details page appears. You can view the execution results on the page.

    Note

    If the execution fails, you can check the logs to identify the cause of the failure and make adjustments.

References

View instance information