@@ -6,9 +6,8 @@ Example Usage
66```hcl
77resource "tencentcloud_private_dns_zone" "foo" {
88 domain = "domain.com"
9- tag_set {
10- tag_key = "created_by"
11- tag_value = "tag"
9+ tags {
10+ "created_by" : "terraform"
1211 }
1312 vpc_set {
1413 region = "ap-guangzhou"
@@ -36,6 +35,8 @@ $ terraform import tencentcloud_private_dns_zone.foo zone_id
3635package tencentcloud
3736
3837import (
38+ "context"
39+ "fmt"
3940 "log"
4041
4142 "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
@@ -62,9 +63,12 @@ func resourceTencentCloudPrivateDnsZone() *schema.Resource {
6263 Description : "Domain name, which must be in the format of standard TLD." ,
6364 },
6465 "tag_set" : {
65- Type : schema .TypeList ,
66- Optional : true ,
67- Description : "Tags the private domain when it is created." ,
66+ Type : schema .TypeList ,
67+ Optional : true ,
68+ Computed : true ,
69+ Description : "Tags the private domain when it is created." ,
70+ Deprecated : "It has been deprecated from version 1.72.4. Use `tags` instead." ,
71+ ConflictsWith : []string {"tags" },
6872 Elem : & schema.Resource {
6973 Schema : map [string ]* schema.Schema {
7074 "tag_key" : {
@@ -80,6 +84,12 @@ func resourceTencentCloudPrivateDnsZone() *schema.Resource {
8084 },
8185 },
8286 },
87+ "tags" : {
88+ Type : schema .TypeMap ,
89+ Optional : true ,
90+ Description : "Tags of the private dns zone." ,
91+ ConflictsWith : []string {"tag_set" },
92+ },
8393 "vpc_set" : {
8494 Type : schema .TypeList ,
8595 Optional : true ,
@@ -147,6 +157,7 @@ func resourceTencentCloudDPrivateDnsZoneCreate(d *schema.ResourceData, meta inte
147157 defer logElapsed ("resource.tencentcloud_private_dns_zone.create" )()
148158
149159 logId := getLogId (contextNil )
160+ ctx := context .WithValue (context .TODO (), logIdKey , logId )
150161
151162 request := privatedns .NewCreatePrivateZoneRequest ()
152163
@@ -213,7 +224,20 @@ func resourceTencentCloudDPrivateDnsZoneCreate(d *schema.ResourceData, meta inte
213224
214225 var response * privatedns.CreatePrivateZoneResponse
215226 response = result
216- d .SetId (* response .Response .ZoneId )
227+
228+ id := * response .Response .ZoneId
229+ d .SetId (id )
230+
231+ client := meta .(* TencentCloudClient ).apiV3Conn
232+ tagService := TagService {client : client }
233+ region := client .Region
234+
235+ if tags := helper .GetTags (d , "tags" ); len (tags ) > 0 {
236+ resourceName := BuildTagResourceName ("privatedns" , "zone" , region , id )
237+ if err := tagService .ModifyTags (ctx , resourceName , tags , nil ); err != nil {
238+ return err
239+ }
240+ }
217241
218242 return resourceTencentCloudDPrivateDnsZoneRead (d , meta )
219243}
@@ -223,6 +247,7 @@ func resourceTencentCloudDPrivateDnsZoneRead(d *schema.ResourceData, meta interf
223247 defer inconsistentCheck (d , meta )()
224248
225249 logId := getLogId (contextNil )
250+ ctx := context .WithValue (context .TODO (), logIdKey , logId )
226251
227252 id := d .Id ()
228253
@@ -259,6 +284,16 @@ func resourceTencentCloudDPrivateDnsZoneRead(d *schema.ResourceData, meta interf
259284 }
260285 _ = d .Set ("tag_set" , tagSets )
261286
287+ client := meta .(* TencentCloudClient ).apiV3Conn
288+ tagService := TagService {client : client }
289+ region := client .Region
290+
291+ tags , err := tagService .DescribeResourceTags (ctx , "privatedns" , "zone" , region , id )
292+ if err != nil {
293+ return err
294+ }
295+ _ = d .Set ("tags" , tags )
296+
262297 vpcSet := make ([]map [string ]interface {}, 0 , len (info .VpcSet ))
263298 for _ , item := range info .VpcSet {
264299 vpcSet = append (vpcSet , map [string ]interface {}{
@@ -286,6 +321,7 @@ func resourceTencentCloudDPrivateDnsZoneUpdate(d *schema.ResourceData, meta inte
286321 defer logElapsed ("resource.tencentcloud_private_dns_zone.update" )()
287322
288323 logId := getLogId (contextNil )
324+ ctx := context .WithValue (context .TODO (), logIdKey , logId )
289325 id := d .Id ()
290326
291327 if d .HasChange ("remark" ) || d .HasChange ("dns_forward_status" ) {
@@ -354,6 +390,27 @@ func resourceTencentCloudDPrivateDnsZoneUpdate(d *schema.ResourceData, meta inte
354390 return err
355391 }
356392 }
393+
394+ if d .HasChange ("tag_set" ) {
395+ return fmt .Errorf ("tag_set do not support change, please use tags instead." )
396+ }
397+
398+ client := meta .(* TencentCloudClient ).apiV3Conn
399+ tagService := TagService {client : client }
400+ region := client .Region
401+
402+ if d .HasChange ("tags" ) {
403+ oldTags , newTags := d .GetChange ("tags" )
404+ replaceTags , deleteTags := diffTags (oldTags .(map [string ]interface {}), newTags .(map [string ]interface {}))
405+
406+ resourceName := BuildTagResourceName ("privatedns" , "zone" , region , id )
407+ if err := tagService .ModifyTags (ctx , resourceName , replaceTags , deleteTags ); err != nil {
408+ return err
409+ }
410+
411+ d .SetPartial ("tags" )
412+ }
413+
357414 return resourceTencentCloudDPrivateDnsZoneRead (d , meta )
358415}
359416
0 commit comments