Skip to content

feat(as): [124198069] tencentcloud_as_scaling_config support tags #3377

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changelog/3377.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:enhancement
resource/tencentcloud_as_scaling_config: support `tags`
```

```release-note:enhancement
resource/tencentcloud_as_scaling_group: fix error while creating multi tags
```
40 changes: 40 additions & 0 deletions tencentcloud/services/as/resource_tc_as_scaling_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"fmt"
"log"

svctag "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/services/tag"

tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common"
svccvm "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/services/cvm"

Expand Down Expand Up @@ -278,6 +280,11 @@ func ResourceTencentCloudAsScalingConfig() *schema.Resource {
Optional: true,
Description: "Dedicated Cluster ID.",
},
"tags": {
Type: schema.TypeMap,
Optional: true,
Description: "Tags of launch configuration.",
},
// Computed values
"status": {
Type: schema.TypeString,
Expand Down Expand Up @@ -514,6 +521,18 @@ func resourceTencentCloudAsScalingConfigCreate(d *schema.ResourceData, meta inte
request.DedicatedClusterId = helper.String(v.(string))
}

if tags := helper.GetTags(d, "tags"); len(tags) > 0 {
for tagKey, tagValue := range tags {
tag := as.Tag{
ResourceType: helper.String("launch-configuration"),
Key: helper.String(tagKey),
Value: helper.String(tagValue),
}

request.Tags = append(request.Tags, &tag)
}
}

var launchConfigurationId string
err := resource.Retry(4*tccommon.WriteRetryTimeout, func() *resource.RetryError {
response, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseAsClient().CreateLaunchConfiguration(request)
Expand Down Expand Up @@ -648,6 +667,10 @@ func resourceTencentCloudAsScalingConfigRead(d *schema.ResourceData, meta interf
_ = d.Set("dedicated_cluster_id", config.DedicatedClusterId)
}

if config.Tags != nil && len(config.Tags) > 0 {
_ = d.Set("tags", flattenTagsMapping(config.Tags))
}

return nil
})
if err != nil {
Expand Down Expand Up @@ -922,6 +945,23 @@ func resourceTencentCloudAsScalingConfigUpdate(d *schema.ResourceData, meta inte
}
}

if d.HasChange("tags") {
ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId)

client := meta.(tccommon.ProviderMeta).GetAPIV3Conn()
tagService := svctag.NewTagService(client)
region := client.Region

oldValue, newValue := d.GetChange("tags")
replaceTags, deleteTags := svctag.DiffTags(oldValue.(map[string]interface{}), newValue.(map[string]interface{}))

resourceName := tccommon.BuildTagResourceName("as", "launch-configuration", region, d.Id())
err := tagService.ModifyTags(ctx, resourceName, replaceTags, deleteTags)
if err != nil {
return err
}
}

err := resource.Retry(4*tccommon.WriteRetryTimeout, func() *resource.RetryError {
response, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseAsClient().ModifyLaunchConfigurationAttributes(request)
if e != nil {
Expand Down
15 changes: 15 additions & 0 deletions tencentcloud/services/as/resource_tc_as_scaling_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ resource "tencentcloud_as_scaling_config" "example" {
instance_tags = {
tag = "example"
}

tags = {
"createdBy" = "Terraform"
"owner" = "tf"
}
}
```

Expand All @@ -60,6 +65,11 @@ resource "tencentcloud_as_scaling_config" "example" {
instance_charge_type = "SPOTPAID"
spot_instance_type = "one-time"
spot_max_price = "1000"

tags = {
"createdBy" = "Terraform"
"owner" = "tf"
}
}
```

Expand Down Expand Up @@ -159,6 +169,11 @@ resource "tencentcloud_as_scaling_config" "example" {
instance_tags = {
tag = "example"
}

tags = {
"createdBy" = "Terraform"
"owner" = "tf"
}
}
```

Expand Down
12 changes: 7 additions & 5 deletions tencentcloud/services/as/resource_tc_as_scaling_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,12 +352,14 @@ func resourceTencentCloudAsScalingGroupCreate(d *schema.ResourceData, meta inter
}

if tags := helper.GetTags(d, "tags"); len(tags) > 0 {
for k, v := range tags {
request.Tags = append(request.Tags, &as.Tag{
for tagKey, tagValue := range tags {
tag := as.Tag{
ResourceType: helper.String("auto-scaling-group"),
Key: &k,
Value: &v,
})
Key: helper.String(tagKey),
Value: helper.String(tagValue),
}

request.Tags = append(request.Tags, &tag)
}
}

Expand Down
8 changes: 8 additions & 0 deletions tencentcloud/services/as/service_tencentcloud_as.go
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,14 @@ func flattenInstanceTagsMapping(list []*as.InstanceTag) map[string]interface{} {
return result
}

func flattenTagsMapping(list []*as.Tag) map[string]interface{} {
result := make(map[string]interface{}, len(list))
for _, v := range list {
result[*v.Key] = *v.Value
}
return result
}

func (me *AsService) DescribeAsAdvices(ctx context.Context, param map[string]interface{}) (advices []*as.AutoScalingAdvice, errRet error) {
var (
logId = tccommon.GetLogId(ctx)
Expand Down
16 changes: 16 additions & 0 deletions website/docs/r/as_scaling_config.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ resource "tencentcloud_as_scaling_config" "example" {
instance_tags = {
tag = "example"
}

tags = {
"createdBy" = "Terraform"
"owner" = "tf"
}
}
```

Expand All @@ -71,6 +76,11 @@ resource "tencentcloud_as_scaling_config" "example" {
instance_charge_type = "SPOTPAID"
spot_instance_type = "one-time"
spot_max_price = "1000"

tags = {
"createdBy" = "Terraform"
"owner" = "tf"
}
}
```

Expand Down Expand Up @@ -169,6 +179,11 @@ resource "tencentcloud_as_scaling_config" "example" {
instance_tags = {
tag = "example"
}

tags = {
"createdBy" = "Terraform"
"owner" = "tf"
}
}
```

Expand Down Expand Up @@ -206,6 +221,7 @@ The following arguments are supported:
* `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`.
* `system_disk_size` - (Optional, Int) Volume of system disk in GB. Default is `50`.
* `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.
* `tags` - (Optional, Map) Tags of launch configuration.
* `user_data` - (Optional, String) ase64-encoded User Data text, the length limit is 16KB.

The `data_disk` object supports the following:
Expand Down
Loading