This topic describes how to modify the value of a tag for multiple resources in OOS. You can modify the tag value of a tag that is bound to hundreds of resources by using a custom template.

Prerequisites

A tag is bound to the resources. For more information, see Create or bind a tag. The tag key-value pair of ECS instances in this example is TagKey:OldTagValue.

Background information

This topic takes ECS instances as an example to create a custom template in OOS. This template allows you to modify the same tag value for hundreds of ECS instances at a time. In this example, the original tag key-value pair of ECS instances is TagKey:OldTagValue. After you modify it, it is changed to TagKey:NewTagValue.
Note
  • You can modify up to 1,000 resources at a time. When the number of resources is greater than 1,000, you must execute the custom template for multiple times.
  • You can use the OOS custom template to modify tag values of any resources to which tags can be bound. You can modify the corresponding API operations of resources based on your business needs. For more information about resources to which tags can be bound, see Tag overview. For more information about resources that OOS supports, see List of supported cloud services.

Procedure

  1. Log on to the OOS console.
  2. In the top navigation bar, select a region.
  3. In the left-side navigation pane, click My Templates.
  4. Click Create Template.
    1. In the Create Template dialog box, select Empty Templates and click OK.
    2. Click JSON to edit the template. Enter TagResourcesFilterByTags in the Template Name field. After you edit the template, click Create Template.

      The sample template is as follows:

      {
          "Description": "Create the policy of modifying a tag for multiple resources",
          "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",
                      "ecs: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": {}
      }

      Parameter description:

      • operateId: The operation ID. It is used to distinguish each operation.
      • tagKey: The current tag key. It is used to filter resources.
      • tagValue: The current tag value. It is used to filter resources.
      • newTagValue: The new tag value. It is the tag value after the update operation.

      Permission description:

      • DescribeInstances: It is used to filter resources by original tag.
      • TagResources: It is used to create or bind tags to a specified resource.
  5. In the left-side navigation pane, click My Templates. Find the custom template TagResourcesFilterByTags and click Create Execution in the Actions column.
    OOSTags
  6. You can keep the default settings or select another execution mode, and click Next: Parameter Settings.
  7. Modify the tag value OldTagValue that matches the tag key TagKey to NewTagValue and click Next: OK.
    save
  8. On the Create Execution page, click Create Execution.
  9. In the right-side Basic Information section, click Execution Result to check the result.
    • If the execution status is Success, it indicates that the tag value is modified.

      success
    • If the execution status is Failed, you can view the execution result and logs to adjust execution information.

      failed