@@ -3,23 +3,56 @@ Provide a resource to create a Private Dns Zone.
33
44Example Usage
55
6+ Create a basic Private Dns Zone
7+
68```hcl
7- resource "tencentcloud_private_dns_zone" "foo" {
9+ resource "tencentcloud_vpc" "vpc" {
10+ name = "vpc-example"
11+ cidr_block = "10.0.0.0/16"
12+ }
13+
14+ resource "tencentcloud_private_dns_zone" "example" {
815 domain = "domain.com"
9- tags {
10- "created_by" : "terraform"
16+ remark = "remark."
17+
18+ vpc_set {
19+ region = "ap-guangzhou"
20+ uniq_vpc_id = tencentcloud_vpc.vpc.id
21+ }
22+
23+ dns_forward_status = "DISABLED"
24+ cname_speedup_status = "ENABLED"
25+
26+ tags = {
27+ createdBy : "terraform"
1128 }
29+ }
30+ ```
31+
32+ Create a Private Dns Zone domain and bind associated accounts'VPC
33+
34+ ```hcl
35+ resource "tencentcloud_private_dns_zone" "example" {
36+ domain = "domain.com"
37+ remark = "remark."
38+
1239 vpc_set {
13- region = "ap-guangzhou"
14- uniq_vpc_id = " vpc-xxxxx"
40+ region = "ap-guangzhou"
41+ uniq_vpc_id = tencentcloud_vpc. vpc.id
1542 }
16- remark = "test"
17- dns_forward_status = "DISABLED"
43+
1844 account_vpc_set {
19- uin = "454xxxxxxx"
20- region = "ap-guangzhou"
21- uniq_vpc_id = "vpc-xxxxx"
22- vpc_name = "test-redis"
45+ uin = "123456789"
46+ uniq_vpc_id = "vpc-adsebmya"
47+ region = "ap-guangzhou"
48+ vpc_name = "vpc-name"
49+ }
50+
51+ dns_forward_status = "DISABLED"
52+ cname_speedup_status = "ENABLED"
53+
54+ tags = {
55+ createdBy : "terraform"
2356 }
2457}
2558```
@@ -117,6 +150,7 @@ func resourceTencentCloudPrivateDnsZone() *schema.Resource {
117150 "dns_forward_status" : {
118151 Type : schema .TypeString ,
119152 Optional : true ,
153+ Default : DNS_FORWARD_STATUS_DISABLED ,
120154 ValidateFunc : validateAllowedStringValue (PRIVATE_DNS_FORWARD_STATUS ),
121155 Description : "Whether to enable subdomain recursive DNS. Valid values: ENABLED, DISABLED. Default value: DISABLED." ,
122156 },
@@ -149,17 +183,25 @@ func resourceTencentCloudPrivateDnsZone() *schema.Resource {
149183 },
150184 },
151185 },
186+ "cname_speedup_status" : {
187+ Type : schema .TypeString ,
188+ Optional : true ,
189+ Default : CNAME_SPEEDUP_STATUS_ENABLED ,
190+ ValidateFunc : validateAllowedStringValue (CNAME_SPEEDUP_STATUS ),
191+ Description : "CNAME acceleration: ENABLED, DISABLED, Default value is ENABLED." ,
192+ },
152193 },
153194 }
154195}
155196
156197func resourceTencentCloudDPrivateDnsZoneCreate (d * schema.ResourceData , meta interface {}) error {
157198 defer logElapsed ("resource.tencentcloud_private_dns_zone.create" )()
158199
159- logId := getLogId (contextNil )
160- ctx := context .WithValue (context .TODO (), logIdKey , logId )
161-
162- request := privatedns .NewCreatePrivateZoneRequest ()
200+ var (
201+ logId = getLogId (contextNil )
202+ ctx = context .WithValue (context .TODO (), logIdKey , logId )
203+ request = privatedns .NewCreatePrivateZoneRequest ()
204+ )
163205
164206 domain := d .Get ("domain" ).(string )
165207 request .Domain = & domain
@@ -215,6 +257,11 @@ func resourceTencentCloudDPrivateDnsZoneCreate(d *schema.ResourceData, meta inte
215257 request .AccountVpcSet = accountVpcSet
216258 }
217259
260+ if v , ok := d .GetOk ("cname_speedup_status" ); ok {
261+ cnameSpeedupStatus := v .(string )
262+ request .CnameSpeedupStatus = helper .String (cnameSpeedupStatus )
263+ }
264+
218265 result , err := meta .(* TencentCloudClient ).apiV3Conn .UsePrivateDnsClient ().CreatePrivateZone (request )
219266
220267 if err != nil {
@@ -245,15 +292,15 @@ func resourceTencentCloudDPrivateDnsZoneRead(d *schema.ResourceData, meta interf
245292 defer logElapsed ("resource.tencentcloud_private_dns_zone.read" )()
246293 defer inconsistentCheck (d , meta )()
247294
248- logId := getLogId ( contextNil )
249- ctx := context . WithValue ( context . TODO (), logIdKey , logId )
250-
251- id := d . Id ()
252-
253- request := privatedns . NewDescribePrivateZoneRequest ()
254- request . ZoneId = helper . String ( id )
295+ var (
296+ logId = getLogId ( contextNil )
297+ ctx = context . WithValue ( context . TODO (), logIdKey , logId )
298+ request = privatedns . NewDescribePrivateZoneRequest ()
299+ response * privatedns. DescribePrivateZoneResponse
300+ id = d . Id ()
301+ )
255302
256- var response * privatedns. DescribePrivateZoneResponse
303+ request . ZoneId = & id
257304
258305 err := resource .Retry (readRetryTimeout , func () * resource.RetryError {
259306 result , e := meta .(* TencentCloudClient ).apiV3Conn .UsePrivateDnsClient ().DescribePrivateZone (request )
@@ -264,6 +311,7 @@ func resourceTencentCloudDPrivateDnsZoneRead(d *schema.ResourceData, meta interf
264311 response = result
265312 return nil
266313 })
314+
267315 if err != nil {
268316 log .Printf ("[CRITAL]%s read DnsPod Domain failed, reason:%s\n " , logId , err .Error ())
269317 return err
@@ -303,6 +351,7 @@ func resourceTencentCloudDPrivateDnsZoneRead(d *schema.ResourceData, meta interf
303351 _ = d .Set ("vpc_set" , vpcSet )
304352 _ = d .Set ("remark" , info .Remark )
305353 _ = d .Set ("dns_forward_status" , info .DnsForwardStatus )
354+ _ = d .Set ("cname_speedup_status" , info .CnameSpeedupStatus )
306355
307356 accountVpcSet := make ([]map [string ]interface {}, 0 , len (info .AccountVpcSet ))
308357 for _ , item := range info .AccountVpcSet {
@@ -319,26 +368,39 @@ func resourceTencentCloudDPrivateDnsZoneRead(d *schema.ResourceData, meta interf
319368func resourceTencentCloudDPrivateDnsZoneUpdate (d * schema.ResourceData , meta interface {}) error {
320369 defer logElapsed ("resource.tencentcloud_private_dns_zone.update" )()
321370
322- logId := getLogId (contextNil )
323- ctx := context .WithValue (context .TODO (), logIdKey , logId )
324- id := d .Id ()
371+ var (
372+ logId = getLogId (contextNil )
373+ ctx = context .WithValue (context .TODO (), logIdKey , logId )
374+ id = d .Id ()
375+ )
376+
377+ if d .HasChange ("tag_set" ) {
378+ return fmt .Errorf ("tag_set do not support change, please use tags instead." )
379+ }
325380
326- if d .HasChange ("remark" ) || d .HasChange ("dns_forward_status" ) {
381+ if d .HasChange ("remark" ) || d .HasChange ("dns_forward_status" ) || d . HasChange ( "cname_speedup_status" ) {
327382 request := privatedns .NewModifyPrivateZoneRequest ()
328- request .ZoneId = helper . String ( id )
383+ request .ZoneId = & id
329384 if v , ok := d .GetOk ("remark" ); ok {
330385 request .Remark = helper .String (v .(string ))
331386 }
387+
332388 if v , ok := d .GetOk ("dns_forward_status" ); ok {
333389 request .DnsForwardStatus = helper .String (v .(string ))
334390 }
391+
392+ if v , ok := d .GetOk ("cname_speedup_status" ); ok {
393+ request .CnameSpeedupStatus = helper .String (v .(string ))
394+ }
395+
335396 err := resource .Retry (readRetryTimeout , func () * resource.RetryError {
336397 _ , e := meta .(* TencentCloudClient ).apiV3Conn .UsePrivateDnsClient ().ModifyPrivateZone (request )
337398 if e != nil {
338399 return retryError (e )
339400 }
340401 return nil
341402 })
403+
342404 if err != nil {
343405 log .Printf ("[CRITAL]%s modify privateDns zone info failed, reason:%s\n " , logId , err .Error ())
344406 return err
@@ -347,7 +409,7 @@ func resourceTencentCloudDPrivateDnsZoneUpdate(d *schema.ResourceData, meta inte
347409
348410 if d .HasChange ("vpc_set" ) || d .HasChange ("account_vpc_set" ) {
349411 request := privatedns .NewModifyPrivateZoneVpcRequest ()
350- request .ZoneId = helper . String ( id )
412+ request .ZoneId = & id
351413 if v , ok := d .GetOk ("vpc_set" ); ok {
352414 var vpcSets = make ([]* privatedns.VpcInfo , 0 )
353415 items := v .([]interface {})
@@ -377,23 +439,22 @@ func resourceTencentCloudDPrivateDnsZoneUpdate(d *schema.ResourceData, meta inte
377439 }
378440 request .AccountVpcSet = accVpcSets
379441 }
442+
380443 err := resource .Retry (readRetryTimeout , func () * resource.RetryError {
381444 _ , e := meta .(* TencentCloudClient ).apiV3Conn .UsePrivateDnsClient ().ModifyPrivateZoneVpc (request )
382445 if e != nil {
383446 return retryError (e )
384447 }
448+
385449 return nil
386450 })
451+
387452 if err != nil {
388453 log .Printf ("[CRITAL]%s modify privateDns zone vpc failed, reason:%s\n " , logId , err .Error ())
389454 return err
390455 }
391456 }
392457
393- if d .HasChange ("tag_set" ) {
394- return fmt .Errorf ("tag_set do not support change, please use tags instead." )
395- }
396-
397458 client := meta .(* TencentCloudClient ).apiV3Conn
398459 tagService := TagService {client : client }
399460 region := client .Region
@@ -415,21 +476,27 @@ func resourceTencentCloudDPrivateDnsZoneUpdate(d *schema.ResourceData, meta inte
415476func resourceTencentCloudDPrivateDnsZoneDelete (d * schema.ResourceData , meta interface {}) error {
416477 defer logElapsed ("resource.tencentcloud_private_dns_zone.delete" )()
417478
418- logId := getLogId (contextNil )
479+ var (
480+ logId = getLogId (contextNil )
481+ request = privatedns .NewDeletePrivateZoneRequest ()
482+ id = d .Id ()
483+ )
419484
420- request := privatedns .NewDeletePrivateZoneRequest ()
421- request .ZoneId = helper .String (d .Id ())
485+ request .ZoneId = & id
422486
423487 err := resource .Retry (writeRetryTimeout , func () * resource.RetryError {
424488 _ , e := meta .(* TencentCloudClient ).apiV3Conn .UsePrivateDnsClient ().DeletePrivateZone (request )
425489 if e != nil {
426490 return retryError (e )
427491 }
492+
428493 return nil
429494 })
495+
430496 if err != nil {
431497 log .Printf ("[CRITAL]%s delete privateDns zone failed, reason:%s\n " , logId , err .Error ())
432498 return err
433499 }
500+
434501 return nil
435502}
0 commit comments