Tagging Multiple Resources
Using the Opscompass CLI and basic scripting, users can tag multiple Opscompass resources in an automated way.
The Opscompass CLI has the versatility to be used in scripts to automate processes such as tagging multiple items. In a situation where you have a list of the Cloud Resource IDs, or the Opscompass IDs, this is an example of how to tag multiple resources. This can be useful so that users can then sort by these
Prerequisites
Opscompass CLI Installed
Getting the Data
The opscompass CLI has two required paramaters. The COMPANY and either the RESOURCE-ID (the cloud resource id) or the ID(the opscompass resource id). You can get the ID by exporting a list of resources from the Inventory in Opscompass. This export will give the user a CSV, with the final item in the list being the link to the resource which includes the ID (ex. https://app.opscompass.com/opscompass/inventory/10206142). Users can use tools like excel to to do a 'TEXTSPLIT' to isolate the IDs from Opscompass.
Similarly, users can get a list of resources from a cloud provider to get the RESOURCE-ID("/subscriptions/8deb6078-c9af-4841-b5c5-b7743c23dbd7/resourceGroups/tutorial").
Tagging the Data
Lets say you get a list of IDs from Opscompass in a file called resources.txt
| 932859 932932 933007 10204213 |
You can set up a simple script, in this case a bash script, to loop through and tag those items using the opscompass commandopscompass resources add-tags --company <name of company in Opscompass> --id <Opscompass resource ID> --tag <tag>
#!/bin/bashFILE="resources.txt"while IFS= read -r line; do opscompass resources add-tags --company opscompass --id $line --tag "example-tag" done < "$FILE" |
These tags will now be attached to the resources in Opscompass.
