@@ -29,6 +29,7 @@ func ResourceTencentCloudPrivateDnsRecord() *schema.Resource {
29
29
"zone_id" : {
30
30
Type : schema .TypeString ,
31
31
Required : true ,
32
+ ForceNew : true ,
32
33
Description : "Private domain ID." ,
33
34
},
34
35
"record_type" : {
@@ -42,10 +43,9 @@ func ResourceTencentCloudPrivateDnsRecord() *schema.Resource {
42
43
Description : "Subdomain, such as \" www\" , \" m\" , and \" @\" ." ,
43
44
},
44
45
"record_value" : {
45
- Type : schema .TypeString ,
46
- Required : true ,
47
- Description : "Record value, such as IP: 192.168.10.2," +
48
- " CNAME: cname.qcloud.com, and MX: mail.qcloud.com.." ,
46
+ Type : schema .TypeString ,
47
+ Required : true ,
48
+ Description : "Record value, such as IP: 192.168.10.2, CNAME: cname.qcloud.com, and MX: mail.qcloud.com." ,
49
49
},
50
50
"weight" : {
51
51
Type : schema .TypeInt ,
@@ -59,10 +59,10 @@ func ResourceTencentCloudPrivateDnsRecord() *schema.Resource {
59
59
" Valid values: 5, 10, 15, 20, 30, 40, 50." ,
60
60
},
61
61
"ttl" : {
62
- Type : schema .TypeInt ,
63
- Optional : true ,
64
- Description : "Record cache time. The smaller the value, the faster the record will take effect." +
65
- " Value range: 1~86400s." ,
62
+ Type : schema .TypeInt ,
63
+ Optional : true ,
64
+ Computed : true ,
65
+ Description : "Record cache time. The smaller the value, the faster the record will take effect. Value range: 1~86400s." ,
66
66
},
67
67
},
68
68
}
@@ -71,42 +71,64 @@ func ResourceTencentCloudPrivateDnsRecord() *schema.Resource {
71
71
func resourceTencentCloudDPrivateDnsRecordCreate (d * schema.ResourceData , meta interface {}) error {
72
72
defer tccommon .LogElapsed ("resource.tencentcloud_private_dns_record.create" )()
73
73
74
- logId := tccommon .GetLogId (tccommon .ContextNil )
74
+ var (
75
+ logId = tccommon .GetLogId (tccommon .ContextNil )
76
+ request = privatedns .NewCreatePrivateZoneRecordRequest ()
77
+ response = privatedns .NewCreatePrivateZoneRecordResponse ()
78
+ zoneId string
79
+ )
75
80
76
- request := privatedns . NewCreatePrivateZoneRecordRequest ()
77
-
78
- zoneId := d . Get ( "zone_id" ) .(string )
79
- request . ZoneId = & zoneId
81
+ if v , ok := d . GetOk ( "zone_id" ); ok {
82
+ request . ZoneId = helper . String ( v .( string ))
83
+ zoneId = v .(string )
84
+ }
80
85
81
- recordType := d .Get ("record_type" ).(string )
82
- request .RecordType = & recordType
86
+ if v , ok := d .GetOk ("record_type" ); ok {
87
+ request .RecordType = helper .String (v .(string ))
88
+ }
83
89
84
- subDomain := d .Get ("sub_domain" ).(string )
85
- request .SubDomain = & subDomain
90
+ if v , ok := d .GetOk ("sub_domain" ); ok {
91
+ request .SubDomain = helper .String (v .(string ))
92
+ }
86
93
87
- recordValue := d .Get ("record_value" ).(string )
88
- request .RecordValue = & recordValue
94
+ if v , ok := d .GetOk ("record_value" ); ok {
95
+ request .RecordValue = helper .String (v .(string ))
96
+ }
89
97
90
- if v , ok := d .GetOk ("weight" ); ok {
98
+ if v , ok := d .GetOkExists ("weight" ); ok {
91
99
request .Weight = helper .Int64 (int64 (v .(int )))
92
100
}
93
101
94
- if v , ok := d .GetOk ("mx" ); ok {
102
+ if v , ok := d .GetOkExists ("mx" ); ok {
95
103
request .MX = helper .Int64 (int64 (v .(int )))
96
104
}
97
- if v , ok := d .GetOk ("ttl" ); ok {
105
+
106
+ if v , ok := d .GetOkExists ("ttl" ); ok {
98
107
request .TTL = helper .Int64 (int64 (v .(int )))
99
108
}
100
109
101
- result , err := meta .(tccommon.ProviderMeta ).GetAPIV3Conn ().UsePrivateDnsClient ().CreatePrivateZoneRecord (request )
110
+ err := resource .Retry (tccommon .WriteRetryTimeout , func () * resource.RetryError {
111
+ result , e := meta .(tccommon.ProviderMeta ).GetAPIV3Conn ().UsePrivateDnsClient ().CreatePrivateZoneRecord (request )
112
+ if e != nil {
113
+ return tccommon .RetryError (e )
114
+ } else {
115
+ log .Printf ("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n " , logId , request .GetAction (), request .ToJsonString (), result .ToJsonString ())
116
+ }
117
+
118
+ if result == nil {
119
+ e = fmt .Errorf ("create PrivateDns record failed" )
120
+ return resource .NonRetryableError (e )
121
+ }
122
+
123
+ response = result
124
+ return nil
125
+ })
102
126
103
127
if err != nil {
104
128
log .Printf ("[CRITAL]%s create PrivateDns record failed, reason:%s\n " , logId , err .Error ())
105
129
return err
106
130
}
107
131
108
- response := result
109
-
110
132
recordId := * response .Response .RecordId
111
133
d .SetId (strings .Join ([]string {zoneId , recordId }, tccommon .FILED_SP ))
112
134
@@ -117,17 +139,17 @@ func resourceTencentCloudDPrivateDnsRecordRead(d *schema.ResourceData, meta inte
117
139
defer tccommon .LogElapsed ("resource.tencentcloud_private_dns_zone.read" )()
118
140
defer tccommon .InconsistentCheck (d , meta )()
119
141
120
- logId := tccommon .GetLogId (tccommon .ContextNil )
121
- ctx := context .WithValue (context .TODO (), tccommon .LogIdKey , logId )
122
-
123
- service := PrivateDnsService {
124
- client : meta .(tccommon.ProviderMeta ).GetAPIV3Conn (),
125
- }
142
+ var (
143
+ logId = tccommon .GetLogId (tccommon .ContextNil )
144
+ ctx = context .WithValue (context .TODO (), tccommon .LogIdKey , logId )
145
+ service = PrivateDnsService {client : meta .(tccommon.ProviderMeta ).GetAPIV3Conn ()}
146
+ )
126
147
127
148
idSplit := strings .Split (d .Id (), tccommon .FILED_SP )
128
149
if len (idSplit ) != 2 {
129
150
return fmt .Errorf ("record id strategy is can't read, id is borken, id is %s" , d .Id ())
130
151
}
152
+
131
153
zoneId := idSplit [0 ]
132
154
recordId := idSplit [1 ]
133
155
@@ -169,73 +191,57 @@ func resourceTencentCloudDPrivateDnsRecordRead(d *schema.ResourceData, meta inte
169
191
func resourceTencentCloudDPrivateDnsRecordUpdate (d * schema.ResourceData , meta interface {}) error {
170
192
defer tccommon .LogElapsed ("resource.tencentcloud_private_dns_record.update" )()
171
193
194
+ var (
195
+ logId = tccommon .GetLogId (tccommon .ContextNil )
196
+ request = privatedns .NewModifyPrivateZoneRecordRequest ()
197
+ )
198
+
172
199
idSplit := strings .Split (d .Id (), tccommon .FILED_SP )
173
200
if len (idSplit ) != 2 {
174
201
return fmt .Errorf ("record id strategy is can't read, id is borken, id is %s" , d .Id ())
175
202
}
176
- logId := tccommon . GetLogId ( tccommon . ContextNil )
203
+
177
204
zoneId := idSplit [0 ]
178
205
recordId := idSplit [1 ]
179
206
180
- request := privatedns .NewModifyPrivateZoneRecordRequest ()
181
207
request .ZoneId = helper .String (zoneId )
182
208
request .RecordId = helper .String (recordId )
183
-
184
- needModify := false
185
- if d .HasChange ("record_type" ) {
186
- needModify = true
209
+ if v , ok := d .GetOk ("record_type" ); ok {
210
+ request .RecordType = helper .String (v .(string ))
187
211
}
188
212
189
- if d . HasChange ("sub_domain" ) {
190
- needModify = true
213
+ if v , ok := d . GetOk ("sub_domain" ); ok {
214
+ request . SubDomain = helper . String ( v .( string ))
191
215
}
192
216
193
- if d . HasChange ("record_value" ) {
194
- needModify = true
217
+ if v , ok := d . GetOk ("record_value" ); ok {
218
+ request . RecordValue = helper . String ( v .( string ))
195
219
}
196
220
197
- if d .HasChange ("weight" ) {
198
- needModify = true
199
- if v , ok := d .GetOk ("weight" ); ok {
200
- request .Weight = helper .Int64 (int64 (v .(int )))
201
- }
221
+ if v , ok := d .GetOk ("weight" ); ok {
222
+ request .Weight = helper .Int64 (int64 (v .(int )))
202
223
}
203
224
204
- if d .HasChange ("mx" ) {
205
- needModify = true
206
- if v , ok := d .GetOk ("mx" ); ok {
207
- request .MX = helper .Int64 (int64 (v .(int )))
208
- }
225
+ if v , ok := d .GetOk ("mx" ); ok {
226
+ request .MX = helper .Int64 (int64 (v .(int )))
209
227
}
210
228
211
- if d .HasChange ("ttl" ) {
212
- needModify = true
213
- if v , ok := d .GetOk ("ttl" ); ok {
214
- request .TTL = helper .Int64 (int64 (v .(int )))
215
- }
229
+ if v , ok := d .GetOk ("ttl" ); ok {
230
+ request .TTL = helper .Int64 (int64 (v .(int )))
216
231
}
217
232
218
- if needModify {
219
- if v , ok := d .GetOk ("record_type" ); ok {
220
- request .RecordType = helper .String (v .(string ))
221
- }
222
- if v , ok := d .GetOk ("sub_domain" ); ok {
223
- request .SubDomain = helper .String (v .(string ))
224
- }
225
- if v , ok := d .GetOk ("record_value" ); ok {
226
- request .RecordValue = helper .String (v .(string ))
227
- }
228
- err := resource .Retry (tccommon .ReadRetryTimeout , func () * resource.RetryError {
229
- _ , e := meta .(tccommon.ProviderMeta ).GetAPIV3Conn ().UsePrivateDnsClient ().ModifyPrivateZoneRecord (request )
230
- if e != nil {
231
- return tccommon .RetryError (e )
232
- }
233
- return nil
234
- })
235
- if err != nil {
236
- log .Printf ("[CRITAL]%s modify privateDns record info failed, reason:%s\n " , logId , err .Error ())
237
- return err
233
+ err := resource .Retry (tccommon .ReadRetryTimeout , func () * resource.RetryError {
234
+ _ , e := meta .(tccommon.ProviderMeta ).GetAPIV3Conn ().UsePrivateDnsClient ().ModifyPrivateZoneRecord (request )
235
+ if e != nil {
236
+ return tccommon .RetryError (e )
238
237
}
238
+
239
+ return nil
240
+ })
241
+
242
+ if err != nil {
243
+ log .Printf ("[CRITAL]%s modify privateDns record info failed, reason:%s\n " , logId , err .Error ())
244
+ return err
239
245
}
240
246
241
247
return resourceTencentCloudDPrivateDnsRecordRead (d , meta )
@@ -244,21 +250,22 @@ func resourceTencentCloudDPrivateDnsRecordUpdate(d *schema.ResourceData, meta in
244
250
func resourceTencentCloudDPrivateDnsRecordDelete (d * schema.ResourceData , meta interface {}) error {
245
251
defer tccommon .LogElapsed ("resource.tencentcloud_private_dns_record.delete" )()
246
252
247
- logId := tccommon .GetLogId (tccommon .ContextNil )
253
+ var (
254
+ logId = tccommon .GetLogId (tccommon .ContextNil )
255
+ request = privatedns .NewDescribePrivateZoneRequest ()
256
+ )
248
257
249
258
idSplit := strings .Split (d .Id (), tccommon .FILED_SP )
250
259
if len (idSplit ) != 2 {
251
260
return fmt .Errorf ("record id strategy is can't read, id is borken, id is %s" , d .Id ())
252
261
}
262
+
253
263
zoneId := idSplit [0 ]
254
264
recordId := idSplit [1 ]
255
265
256
266
// unbind
257
- request := privatedns .NewDescribePrivateZoneRequest ()
258
- request .ZoneId = helper .String (zoneId )
259
-
260
267
var response * privatedns.DescribePrivateZoneResponse
261
-
268
+ request . ZoneId = helper . String ( zoneId )
262
269
err := resource .Retry (tccommon .ReadRetryTimeout , func () * resource.RetryError {
263
270
result , e := meta .(tccommon.ProviderMeta ).GetAPIV3Conn ().UsePrivateDnsClient ().DescribePrivateZone (request )
264
271
if e != nil {
@@ -268,6 +275,7 @@ func resourceTencentCloudDPrivateDnsRecordDelete(d *schema.ResourceData, meta in
268
275
response = result
269
276
return nil
270
277
})
278
+
271
279
if err != nil {
272
280
log .Printf ("[CRITAL]%s read private dns failed, reason:%s\n " , logId , err .Error ())
273
281
return err
@@ -287,8 +295,10 @@ func resourceTencentCloudDPrivateDnsRecordDelete(d *schema.ResourceData, meta in
287
295
if e != nil {
288
296
return tccommon .RetryError (e )
289
297
}
298
+
290
299
return nil
291
300
})
301
+
292
302
if err != nil {
293
303
log .Printf ("[CRITAL]%s unbind privateDns zone vpc failed, reason:%s\n " , logId , err .Error ())
294
304
return err
@@ -304,8 +314,10 @@ func resourceTencentCloudDPrivateDnsRecordDelete(d *schema.ResourceData, meta in
304
314
if e != nil {
305
315
return tccommon .RetryError (e )
306
316
}
317
+
307
318
return nil
308
319
})
320
+
309
321
if err != nil {
310
322
log .Printf ("[CRITAL]%s delete privateDns record failed, reason:%s\n " , logId , err .Error ())
311
323
return err
@@ -333,8 +345,10 @@ func resourceTencentCloudDPrivateDnsRecordDelete(d *schema.ResourceData, meta in
333
345
if e != nil {
334
346
return tccommon .RetryError (e )
335
347
}
348
+
336
349
return nil
337
350
})
351
+
338
352
if err != nil {
339
353
log .Printf ("[CRITAL]%s rebind privateDns zone vpc failed, reason:%s\n " , logId , err .Error ())
340
354
return err
0 commit comments