Skip to content

Commit 8793d95

Browse files
authored
feat(as): [124198069] tencentcloud_as_scaling_config support tags (#3377)
* add tags * add tags
1 parent b343ece commit 8793d95

6 files changed

+93
-5
lines changed

.changelog/3377.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
```release-note:enhancement
2+
resource/tencentcloud_as_scaling_config: support `tags`
3+
```
4+
5+
```release-note:enhancement
6+
resource/tencentcloud_as_scaling_group: fix error while creating multi tags
7+
```

tencentcloud/services/as/resource_tc_as_scaling_config.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"fmt"
66
"log"
77

8+
svctag "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/services/tag"
9+
810
tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common"
911
svccvm "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/services/cvm"
1012

@@ -278,6 +280,11 @@ func ResourceTencentCloudAsScalingConfig() *schema.Resource {
278280
Optional: true,
279281
Description: "Dedicated Cluster ID.",
280282
},
283+
"tags": {
284+
Type: schema.TypeMap,
285+
Optional: true,
286+
Description: "Tags of launch configuration.",
287+
},
281288
// Computed values
282289
"status": {
283290
Type: schema.TypeString,
@@ -514,6 +521,18 @@ func resourceTencentCloudAsScalingConfigCreate(d *schema.ResourceData, meta inte
514521
request.DedicatedClusterId = helper.String(v.(string))
515522
}
516523

524+
if tags := helper.GetTags(d, "tags"); len(tags) > 0 {
525+
for tagKey, tagValue := range tags {
526+
tag := as.Tag{
527+
ResourceType: helper.String("launch-configuration"),
528+
Key: helper.String(tagKey),
529+
Value: helper.String(tagValue),
530+
}
531+
532+
request.Tags = append(request.Tags, &tag)
533+
}
534+
}
535+
517536
var launchConfigurationId string
518537
err := resource.Retry(4*tccommon.WriteRetryTimeout, func() *resource.RetryError {
519538
response, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseAsClient().CreateLaunchConfiguration(request)
@@ -648,6 +667,10 @@ func resourceTencentCloudAsScalingConfigRead(d *schema.ResourceData, meta interf
648667
_ = d.Set("dedicated_cluster_id", config.DedicatedClusterId)
649668
}
650669

670+
if config.Tags != nil && len(config.Tags) > 0 {
671+
_ = d.Set("tags", flattenTagsMapping(config.Tags))
672+
}
673+
651674
return nil
652675
})
653676
if err != nil {
@@ -922,6 +945,23 @@ func resourceTencentCloudAsScalingConfigUpdate(d *schema.ResourceData, meta inte
922945
}
923946
}
924947

948+
if d.HasChange("tags") {
949+
ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
950+
951+
client := meta.(tccommon.ProviderMeta).GetAPIV3Conn()
952+
tagService := svctag.NewTagService(client)
953+
region := client.Region
954+
955+
oldValue, newValue := d.GetChange("tags")
956+
replaceTags, deleteTags := svctag.DiffTags(oldValue.(map[string]interface{}), newValue.(map[string]interface{}))
957+
958+
resourceName := tccommon.BuildTagResourceName("as", "launch-configuration", region, d.Id())
959+
err := tagService.ModifyTags(ctx, resourceName, replaceTags, deleteTags)
960+
if err != nil {
961+
return err
962+
}
963+
}
964+
925965
err := resource.Retry(4*tccommon.WriteRetryTimeout, func() *resource.RetryError {
926966
response, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseAsClient().ModifyLaunchConfigurationAttributes(request)
927967
if e != nil {

tencentcloud/services/as/resource_tc_as_scaling_config.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ resource "tencentcloud_as_scaling_config" "example" {
4242
instance_tags = {
4343
tag = "example"
4444
}
45+
46+
tags = {
47+
"createdBy" = "Terraform"
48+
"owner" = "tf"
49+
}
4550
}
4651
```
4752

@@ -60,6 +65,11 @@ resource "tencentcloud_as_scaling_config" "example" {
6065
instance_charge_type = "SPOTPAID"
6166
spot_instance_type = "one-time"
6267
spot_max_price = "1000"
68+
69+
tags = {
70+
"createdBy" = "Terraform"
71+
"owner" = "tf"
72+
}
6373
}
6474
```
6575

@@ -159,6 +169,11 @@ resource "tencentcloud_as_scaling_config" "example" {
159169
instance_tags = {
160170
tag = "example"
161171
}
172+
173+
tags = {
174+
"createdBy" = "Terraform"
175+
"owner" = "tf"
176+
}
162177
}
163178
```
164179

tencentcloud/services/as/resource_tc_as_scaling_group.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -352,12 +352,14 @@ func resourceTencentCloudAsScalingGroupCreate(d *schema.ResourceData, meta inter
352352
}
353353

354354
if tags := helper.GetTags(d, "tags"); len(tags) > 0 {
355-
for k, v := range tags {
356-
request.Tags = append(request.Tags, &as.Tag{
355+
for tagKey, tagValue := range tags {
356+
tag := as.Tag{
357357
ResourceType: helper.String("auto-scaling-group"),
358-
Key: &k,
359-
Value: &v,
360-
})
358+
Key: helper.String(tagKey),
359+
Value: helper.String(tagValue),
360+
}
361+
362+
request.Tags = append(request.Tags, &tag)
361363
}
362364
}
363365

tencentcloud/services/as/service_tencentcloud_as.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,14 @@ func flattenInstanceTagsMapping(list []*as.InstanceTag) map[string]interface{} {
648648
return result
649649
}
650650

651+
func flattenTagsMapping(list []*as.Tag) map[string]interface{} {
652+
result := make(map[string]interface{}, len(list))
653+
for _, v := range list {
654+
result[*v.Key] = *v.Value
655+
}
656+
return result
657+
}
658+
651659
func (me *AsService) DescribeAsAdvices(ctx context.Context, param map[string]interface{}) (advices []*as.AutoScalingAdvice, errRet error) {
652660
var (
653661
logId = tccommon.GetLogId(ctx)

website/docs/r/as_scaling_config.html.markdown

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ resource "tencentcloud_as_scaling_config" "example" {
5353
instance_tags = {
5454
tag = "example"
5555
}
56+
57+
tags = {
58+
"createdBy" = "Terraform"
59+
"owner" = "tf"
60+
}
5661
}
5762
```
5863

@@ -71,6 +76,11 @@ resource "tencentcloud_as_scaling_config" "example" {
7176
instance_charge_type = "SPOTPAID"
7277
spot_instance_type = "one-time"
7378
spot_max_price = "1000"
79+
80+
tags = {
81+
"createdBy" = "Terraform"
82+
"owner" = "tf"
83+
}
7484
}
7585
```
7686

@@ -169,6 +179,11 @@ resource "tencentcloud_as_scaling_config" "example" {
169179
instance_tags = {
170180
tag = "example"
171181
}
182+
183+
tags = {
184+
"createdBy" = "Terraform"
185+
"owner" = "tf"
186+
}
172187
}
173188
```
174189

@@ -206,6 +221,7 @@ The following arguments are supported:
206221
* `spot_max_price` - (Optional, String) Max price of a spot instance, is the format of decimal string, for example "0.50". Note: it only works when instance_charge_type is set to `SPOTPAID`.
207222
* `system_disk_size` - (Optional, Int) Volume of system disk in GB. Default is `50`.
208223
* `system_disk_type` - (Optional, String) Type of a CVM disk. Valid values: `CLOUD_PREMIUM` and `CLOUD_SSD`. Default is `CLOUD_PREMIUM`. valid when disk_type_policy is ORIGINAL.
224+
* `tags` - (Optional, Map) Tags of launch configuration.
209225
* `user_data` - (Optional, String) ase64-encoded User Data text, the length limit is 16KB.
210226

211227
The `data_disk` object supports the following:

0 commit comments

Comments
 (0)