Batch modify resource tag value based on OOS

Time:2019-12-2

scene

When there is a label key on resources: Department, label value: retail, how to quickly batch modify the label (key: Department, value: retail) to label (key: Department, value: new retail) due to department resource integration?

background information

Operation and maintenance choreography service OOS defines the operation and maintenance tasks you need to choreograph through templates. Template content supports yaml and JSON formats, and templates are divided into public template and custom template. In order to facilitate your quick use of OOS, OOS provides public templates for your direct use and reference.. Before using the template, you need to carefully review the operation and maintenance tasks to be performed by the template, and give priority to observing the use effect in the test environment.

You can also write custom templates to write the operation and maintenance tasks you need. For more details, see template structure. Tagresourcesfilterbytags in this article is a custom template

Operation steps

Log in to the ECS management console.
On the left navigation bar, selectOperation, maintenance and monitoring > Operation and maintenance arrangement
In the top status bar, selectregion
ChoiceMy templateClickCreate template
ChoiceJSON
The following example is to update the tag value for ECS instance and redis instance
Operateid: Operation ID, distinguish each operation use
Tagkey: tag key, used to filter resources
Tagvalue: tag value, used to filter resources
Tagkey: tag key, to modify the target tag key
Newtagvalue: new tag value, the tag value to be modified

{
    "Description": "finding resources and updating labels based on labels",
    "FormatVersion": "OOS-2019-06-01",
    "Parameters": {
        "operateId": {
            "Description": "operation ID, caller defined",
            "Type": "String",
            "MinLength": 1,
            "MaxLength": 64
        },
        "tagKey": {
            "Description": "current key",
            "Type": "String",
            "MinLength": 1,
            "MaxLength": 64
        },
        "tagValue": {
            "Description": "current value",
            "Type": "String",
            "MinLength": 1,
            "MaxLength": 64
        },
        "newTagValue": {
            "Description": "updated value",
            "Type": "String",
            "MinLength": 1,
            "MaxLength": 64
        }
    },
    "Tasks": [
        {
            "Name": "DescribeInstances_ECS",
            "Action": "ACS::ExecuteAPI",
            "Description": {
                "Zh CN": "filtering ECS instances through tags",
                "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": {
                "Zh CN": "updating ECS instance labels",
                "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}}"
            }
        },
        {
            "OnError": "ACS::NEXT",
            "Name": "DescribeInstances_REDIS",
            "Action": "ACS::ExecuteApi",
            "Description": {
                "Zh CN": "filtering redis instances through tags",
                "en": "filter redis(kvstore) instances by tags"
            },
            "Properties": {
                "Service": "R-kvstore",
                "API": "DescribeInstances",
                "AutoPaging": true,
                "Parameters": {
                    "Tags": [
                        {
                            "Key": "{{ tagKey }}",
                            "Value": "{{ tagValue }}"
                        }
                    ]
                }
            },
            "Outputs": {
                "Instances": {
                    "Type": "List",
                    "ValueSelector": "Instances.KVStoreInstance[].InstanceId"
                }
            }
        },
        {
            "Name": "TagResources_REDIS_Instances",
            "Action": "ACS::ExecuteAPI",
            "Description": {
                "Zh CN": "updating the redis instance label",
                "en": "tag redis instances"
            },
            "Properties": {
                "Service": "R-kvstore",
                "API": "TagResources",
                "Parameters": {
                    "Tags": [
                        {
                            "Key": "{{ tagKey }}",
                            "Value": "{{ newTagValue }}"
                        }
                    ],
                    "ResourceType": "Instance",
                    "ResourceIds": [
                        "{{ACS::TaskLoopItem}}"
                    ]
                }
            },
            "Loop": {
                "MaxErrors": "100%",
                "Concurrency": 20,
                "Items": "{{DescribeInstances_REDIS.Instances}}"
            }
        }
    ],
    "Outputs": {}
}

Create execution:

Batch modify resource tag value based on OOS

Execution details:

Batch modify resource tag value based on OOS

When the execution status shows success, it indicates that the operation and maintenance task has been completed.
When the execution status display fails, you can click the details under the operation column to view the execution log, and analyze and adjust the execution content according to the log information.

According to the code in this article, you can modify it to the cases you need.

Related documents

Tag your RDS resources
Tag your SLB resources
Tag your ECS resources
How to check if your resource has the label you specified?
Batch management of resources based on tags
Support label products and their documents
Label best practices
Practice of batch starting ECS instance based on label through OOS
How to use tags to control access to ECS resources?
Retrieving resources using tags
Create resource label group settings
ECS global label practice
ECS console cloud resource group management – global label


Author: Luo Xiaomeng

Read the original text

This is the original content of yunqi community, which can not be reproduced without permission

Recommended Today

Manjaro uses SS method (requires nodejs environment)

Just installed manjaro, need to installshadowsocks-qt5+Proxy SwitchyOmega, but the latest Chrome has long blocked the installation of non Google store CRX channels. Here is my solution, which is troublesome but usable. If you are familiar with NPM commands in nodejs, you won’t find it troublesome, because nodejs is used for compilation. Preparation environment: A VPS […]