tencent cloud

All product documents
Last updated: 2024-12-02 16:01:33
Tagging
Last updated: 2024-12-02 16:01:33
Tag is a cloud resource management tool that exists in the format of key:values. It can be associated with most of your Tencent Cloud resources, greatly simplifying resource categorization, search, and aggregation.In Terraform, a resource tag is defined through Map:
resource "tencentcloud_instance" "cvm" {
tags = {
key1: "val1",
key2: "val2"
}
}

Tag code implementation

A resource tag can be added via TencentCloud API in two ways. One is using the CreateAPI parameter:
rsType := "instance"

request := cvm.NewRunInstanceRequest()
request.TagSpecification = append(request.TagSpecification, &cvm.TagSpecification{
ResourceType: &rsType,
Tags: []*cvm.Tag{
{
Key: &key,
Value: &value,
},
},
})
Currently, only certain resource creation APIs support passing in tags, with different data structures. To unify the management of the tag code, the second way is used, that is, calling the tag API after creation for association. The input parameter is the six-segment resource description in the following format:
qcs:<project_id, which is left empty here>:<Module>:<Region>:<Account/UIN>:<Resource/ID>
For example, to modify the tag associated with a VPC instance, use the following input parameter:
qcs::vpc:ap-singapore:uin/:vpc/vpc-xxxxxxxx
In the code, just call the encapsulated ModifyTags:
package main

func ResourceTencentCloudVPCUpdate(d *schema.ResourceData, meta interface{}) {
ctx := context.TODO()
region := meta.(*TencentCloudClient).apiV3Conn.Region
id := d.Id()

resourceName := fmt.Sprintf("qcs::vpc:%s:uin/:vpc/%s", region, id)
replaceTags, deleteTags := diffTags(oldTags.(map[string]interface{}), newTags.(map[string]interface{}))

if err := tagService.ModifyTags(ctx, resourceName, replaceTags, deleteTags); err != nil {
return err
}
}
Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback

Contact Us

Contact our sales team or business advisors to help your business.

Technical Support

Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

7x24 Phone Support
Hong Kong, China
+852 800 906 020 (Toll Free)
United States
+1 844 606 0804 (Toll Free)
United Kingdom
+44 808 196 4551 (Toll Free)
Canada
+1 888 605 7930 (Toll Free)
Australia
+61 1300 986 386 (Toll Free)
EdgeOne hotline
+852 300 80699
More local hotlines coming soon