|
9 | 9 |
|
10 | 10 | tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common"
|
11 | 11 | svccrs "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/services/crs"
|
| 12 | + svctag "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/services/tag" |
12 | 13 |
|
13 | 14 | postgresql "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/postgres/v20170312"
|
14 | 15 |
|
@@ -132,11 +133,12 @@ func ResourceTencentCloudPostgresqlReadonlyInstance() *schema.Resource {
|
132 | 133 | ForceNew: true,
|
133 | 134 | Description: "Whether to support IPv6 address access. Valid values: 1 (yes), 0 (no).",
|
134 | 135 | },
|
135 |
| - //"tag_list": { |
136 |
| - // Type: schema.TypeMap, |
137 |
| - // Optional: true, |
138 |
| - // Description: "The information of tags to be associated with instances. This parameter is left empty by default..", |
139 |
| - //}, |
| 136 | + "tags": { |
| 137 | + Type: schema.TypeMap, |
| 138 | + Optional: true, |
| 139 | + Computed: true, |
| 140 | + Description: "Tags.", |
| 141 | + }, |
140 | 142 | "read_only_group_id": {
|
141 | 143 | Type: schema.TypeString,
|
142 | 144 | Optional: true,
|
@@ -252,14 +254,6 @@ func resourceTencentCloudPostgresqlReadOnlyInstanceCreate(d *schema.ResourceData
|
252 | 254 | if v, ok := d.GetOk("dedicated_cluster_id"); ok {
|
253 | 255 | request.DedicatedClusterId = helper.String(v.(string))
|
254 | 256 | }
|
255 |
| - //if tags := helper.GetTags(d, "tag_list"); len(tags) > 0 { |
256 |
| - // for k, v := range tags { |
257 |
| - // request.TagList = &postgresql.Tag{ |
258 |
| - // TagKey: &k, |
259 |
| - // TagValue: &v, |
260 |
| - // } |
261 |
| - // } |
262 |
| - //} |
263 | 257 |
|
264 | 258 | // get specCode with db_version and memory
|
265 | 259 | var allowVersion, allowSpec []string
|
@@ -366,6 +360,15 @@ func resourceTencentCloudPostgresqlReadOnlyInstanceCreate(d *schema.ResourceData
|
366 | 360 | return err
|
367 | 361 | }
|
368 | 362 |
|
| 363 | + if tags := helper.GetTags(d, "tags"); len(tags) > 0 { |
| 364 | + tcClient := meta.(tccommon.ProviderMeta).GetAPIV3Conn() |
| 365 | + tagService := svctag.NewTagService(tcClient) |
| 366 | + resourceName := tccommon.BuildTagResourceName("postgres", "DBInstanceId", tcClient.Region, d.Id()) |
| 367 | + if err := tagService.ModifyTags(ctx, resourceName, tags, nil); err != nil { |
| 368 | + return err |
| 369 | + } |
| 370 | + } |
| 371 | + |
369 | 372 | return resourceTencentCloudPostgresqlReadOnlyInstanceRead(d, meta)
|
370 | 373 | }
|
371 | 374 |
|
@@ -437,11 +440,14 @@ func resourceTencentCloudPostgresqlReadOnlyInstanceRead(d *schema.ResourceData,
|
437 | 440 | _ = d.Set("security_groups_ids", sg)
|
438 | 441 | }
|
439 | 442 |
|
440 |
| - //tags := make(map[string]string, len(instance.TagList)) |
441 |
| - //for _, tag := range instance.TagList { |
442 |
| - // tags[*tag.TagKey] = *tag.TagValue |
443 |
| - //} |
444 |
| - //_ = d.Set("tag_list", tags) |
| 443 | + tcClient := meta.(tccommon.ProviderMeta).GetAPIV3Conn() |
| 444 | + tagService := svctag.NewTagService(tcClient) |
| 445 | + tags, err := tagService.DescribeResourceTags(ctx, "postgres", "DBInstanceId", tcClient.Region, d.Id()) |
| 446 | + if err != nil { |
| 447 | + return err |
| 448 | + } |
| 449 | + |
| 450 | + _ = d.Set("tags", tags) |
445 | 451 |
|
446 | 452 | // computed
|
447 | 453 | _ = d.Set("create_time", instance.CreateTime)
|
@@ -616,20 +622,18 @@ func resourceTencentCloudPostgresqlReadOnlyInstanceUpdate(d *schema.ResourceData
|
616 | 622 |
|
617 | 623 | }
|
618 | 624 |
|
619 |
| - //if d.HasChange("tags") { |
620 |
| - // |
621 |
| - // oldValue, newValue := d.GetChange("tags") |
622 |
| - // replaceTags, deleteTags := diffTags(oldValue.(map[string]interface{}), newValue.(map[string]interface{})) |
623 |
| - // |
624 |
| - // tcClient := meta.(tccommon.ProviderMeta).GetAPIV3Conn() |
625 |
| - // tagService := svctag.NewTagService(tcClient) |
626 |
| - // resourceName := tccommon.BuildTagResourceName("postgres", "DBInstanceId", tcClient.Region, d.Id()) |
627 |
| - // err := tagService.ModifyTags(ctx, resourceName, replaceTags, deleteTags) |
628 |
| - // if err != nil { |
629 |
| - // return err |
630 |
| - // } |
631 |
| - // |
632 |
| - //} |
| 625 | + if d.HasChange("tags") { |
| 626 | + oldValue, newValue := d.GetChange("tags") |
| 627 | + replaceTags, deleteTags := svctag.DiffTags(oldValue.(map[string]interface{}), newValue.(map[string]interface{})) |
| 628 | + |
| 629 | + tcClient := meta.(tccommon.ProviderMeta).GetAPIV3Conn() |
| 630 | + tagService := svctag.NewTagService(tcClient) |
| 631 | + resourceName := tccommon.BuildTagResourceName("postgres", "DBInstanceId", tcClient.Region, d.Id()) |
| 632 | + err := tagService.ModifyTags(ctx, resourceName, replaceTags, deleteTags) |
| 633 | + if err != nil { |
| 634 | + return err |
| 635 | + } |
| 636 | + } |
633 | 637 |
|
634 | 638 | d.Partial(false)
|
635 | 639 |
|
|
0 commit comments