@@ -47,22 +47,29 @@ func ResourceTencentCloudPrivateDnsRecord() *schema.Resource {
47
47
Description : "Record value, such as IP: 192.168.10.2, CNAME: cname.qcloud.com, and MX: mail.qcloud.com." ,
48
48
},
49
49
"weight" : {
50
- Type : schema .TypeInt ,
51
- Optional : true ,
52
- Description : "Record weight. Value range: 1~100." ,
50
+ Type : schema .TypeInt ,
51
+ Optional : true ,
52
+ ValidateFunc : tccommon .ValidateIntegerInRange (1 , 100 ),
53
+ Description : "Record weight. Value range: 1~100." ,
53
54
},
54
55
"mx" : {
55
- Type : schema .TypeInt ,
56
- Optional : true ,
57
- Description : "MX priority, which is required when the record type is MX." +
58
- " Valid values: 5, 10, 15, 20, 30, 40, 50." ,
56
+ Type : schema .TypeInt ,
57
+ Optional : true ,
58
+ Description : "MX priority, which is required when the record type is MX. Valid values: 5, 10, 15, 20, 30, 40, 50." ,
59
59
},
60
60
"ttl" : {
61
61
Type : schema .TypeInt ,
62
62
Optional : true ,
63
63
Computed : true ,
64
64
Description : "Record cache time. The smaller the value, the faster the record will take effect. Value range: 1~86400s." ,
65
65
},
66
+ "status" : {
67
+ Type : schema .TypeString ,
68
+ Optional : true ,
69
+ Computed : true ,
70
+ ValidateFunc : tccommon .ValidateAllowedStringValue ([]string {"enabled" , "disabled" }),
71
+ Description : "Record status. Valid values: `enabled`, `disabled`." ,
72
+ },
66
73
},
67
74
}
68
75
}
@@ -130,14 +137,39 @@ func resourceTencentCloudDPrivateDnsRecordCreate(d *schema.ResourceData, meta in
130
137
}
131
138
132
139
recordId := * response .Response .RecordId
140
+ d .SetId (strings .Join ([]string {zoneId , recordId }, tccommon .FILED_SP ))
133
141
134
142
// wait
135
143
_ , err = service .DescribePrivateDnsRecordById (ctx , zoneId , recordId )
136
144
if err != nil {
137
145
return err
138
146
}
139
147
140
- d .SetId (strings .Join ([]string {zoneId , recordId }, tccommon .FILED_SP ))
148
+ // set record status
149
+ if v , ok := d .GetOk ("status" ); ok {
150
+ status := v .(string )
151
+ if status == "disabled" {
152
+ request := privatedns .NewModifyRecordsStatusRequest ()
153
+ request .ZoneId = & zoneId
154
+ request .RecordIds = []* int64 {helper .StrToInt64Point (recordId )}
155
+ request .Status = helper .String (status )
156
+ err := resource .Retry (tccommon .WriteRetryTimeout , func () * resource.RetryError {
157
+ result , e := meta .(tccommon.ProviderMeta ).GetAPIV3Conn ().UsePrivateDnsClient ().ModifyRecordsStatus (request )
158
+ if e != nil {
159
+ return tccommon .RetryError (e , PRIVATEDNS_CUSTOM_RETRY_SDK_ERROR ... )
160
+ } else {
161
+ log .Printf ("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n " , logId , request .GetAction (), request .ToJsonString (), result .ToJsonString ())
162
+ }
163
+
164
+ return nil
165
+ })
166
+
167
+ if err != nil {
168
+ log .Printf ("[CRITAL]%s modify PrivateDns record status failed, reason:%s\n " , logId , err .Error ())
169
+ return err
170
+ }
171
+ }
172
+ }
141
173
142
174
return resourceTencentCloudDPrivateDnsRecordRead (d , meta )
143
175
}
@@ -179,15 +211,24 @@ func resourceTencentCloudDPrivateDnsRecordRead(d *schema.ResourceData, meta inte
179
211
_ = d .Set ("mx" , record .MX )
180
212
_ = d .Set ("ttl" , record .TTL )
181
213
214
+ if record .Enabled != nil {
215
+ if * record .Enabled == 1 {
216
+ _ = d .Set ("status" , "enabled" )
217
+ } else {
218
+ _ = d .Set ("status" , "disabled" )
219
+ }
220
+ }
221
+
182
222
return nil
183
223
}
184
224
185
225
func resourceTencentCloudDPrivateDnsRecordUpdate (d * schema.ResourceData , meta interface {}) error {
186
226
defer tccommon .LogElapsed ("resource.tencentcloud_private_dns_record.update" )()
187
227
188
228
var (
189
- logId = tccommon .GetLogId (tccommon .ContextNil )
190
- request = privatedns .NewModifyPrivateZoneRecordRequest ()
229
+ logId = tccommon .GetLogId (tccommon .ContextNil )
230
+ request = privatedns .NewModifyPrivateZoneRecordRequest ()
231
+ needChange bool
191
232
)
192
233
193
234
idSplit := strings .Split (d .Id (), tccommon .FILED_SP )
@@ -198,44 +239,78 @@ func resourceTencentCloudDPrivateDnsRecordUpdate(d *schema.ResourceData, meta in
198
239
zoneId := idSplit [0 ]
199
240
recordId := idSplit [1 ]
200
241
201
- request .ZoneId = helper .String (zoneId )
202
- request .RecordId = helper .String (recordId )
203
- if v , ok := d .GetOk ("record_type" ); ok {
204
- request .RecordType = helper .String (v .(string ))
242
+ mutableArgs := []string {"record_type" , "sub_domain" , "record_value" , "weight" , "mx" , "ttl" }
243
+ for _ , v := range mutableArgs {
244
+ if d .HasChange (v ) {
245
+ needChange = true
246
+ break
247
+ }
205
248
}
206
249
207
- if v , ok := d .GetOk ("sub_domain" ); ok {
208
- request .SubDomain = helper .String (v .(string ))
209
- }
250
+ if needChange {
251
+ if v , ok := d .GetOk ("record_type" ); ok {
252
+ request .RecordType = helper .String (v .(string ))
253
+ }
210
254
211
- if v , ok := d .GetOk ("record_value " ); ok {
212
- request .RecordValue = helper .String (v .(string ))
213
- }
255
+ if v , ok := d .GetOk ("sub_domain " ); ok {
256
+ request .SubDomain = helper .String (v .(string ))
257
+ }
214
258
215
- if v , ok := d .GetOk ("weight " ); ok {
216
- request .Weight = helper .Int64 ( int64 ( v .(int ) ))
217
- }
259
+ if v , ok := d .GetOk ("record_value " ); ok {
260
+ request .RecordValue = helper .String ( v .(string ))
261
+ }
218
262
219
- if v , ok := d .GetOk ( "mx " ); ok {
220
- request .MX = helper .Int64 (int64 (v .(int )))
221
- }
263
+ if v , ok := d .GetOkExists ( "weight " ); ok {
264
+ request .Weight = helper .Int64 (int64 (v .(int )))
265
+ }
222
266
223
- if v , ok := d .GetOk ( "ttl " ); ok {
224
- request .TTL = helper .Int64 (int64 (v .(int )))
225
- }
267
+ if v , ok := d .GetOkExists ( "mx " ); ok {
268
+ request .MX = helper .Int64 (int64 (v .(int )))
269
+ }
226
270
227
- err := resource .Retry (tccommon .WriteRetryTimeout , func () * resource.RetryError {
228
- _ , e := meta .(tccommon.ProviderMeta ).GetAPIV3Conn ().UsePrivateDnsClient ().ModifyPrivateZoneRecord (request )
229
- if e != nil {
230
- return tccommon .RetryError (e , PRIVATEDNS_CUSTOM_RETRY_SDK_ERROR ... )
271
+ if v , ok := d .GetOkExists ("ttl" ); ok {
272
+ request .TTL = helper .Int64 (int64 (v .(int )))
231
273
}
232
274
233
- return nil
234
- })
275
+ request .ZoneId = helper .String (zoneId )
276
+ request .RecordId = helper .String (recordId )
277
+ err := resource .Retry (tccommon .WriteRetryTimeout , func () * resource.RetryError {
278
+ _ , e := meta .(tccommon.ProviderMeta ).GetAPIV3Conn ().UsePrivateDnsClient ().ModifyPrivateZoneRecord (request )
279
+ if e != nil {
280
+ return tccommon .RetryError (e , PRIVATEDNS_CUSTOM_RETRY_SDK_ERROR ... )
281
+ }
235
282
236
- if err != nil {
237
- log .Printf ("[CRITAL]%s modify privateDns record info failed, reason:%s\n " , logId , err .Error ())
238
- return err
283
+ return nil
284
+ })
285
+
286
+ if err != nil {
287
+ log .Printf ("[CRITAL]%s modify privateDns record info failed, reason:%s\n " , logId , err .Error ())
288
+ return err
289
+ }
290
+ }
291
+
292
+ if d .HasChange ("status" ) {
293
+ if v , ok := d .GetOk ("status" ); ok {
294
+ request := privatedns .NewModifyRecordsStatusRequest ()
295
+ request .ZoneId = & zoneId
296
+ request .RecordIds = []* int64 {helper .StrToInt64Point (recordId )}
297
+ request .Status = helper .String (v .(string ))
298
+ err := resource .Retry (tccommon .WriteRetryTimeout , func () * resource.RetryError {
299
+ result , e := meta .(tccommon.ProviderMeta ).GetAPIV3Conn ().UsePrivateDnsClient ().ModifyRecordsStatus (request )
300
+ if e != nil {
301
+ return tccommon .RetryError (e , PRIVATEDNS_CUSTOM_RETRY_SDK_ERROR ... )
302
+ } else {
303
+ log .Printf ("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n " , logId , request .GetAction (), request .ToJsonString (), result .ToJsonString ())
304
+ }
305
+
306
+ return nil
307
+ })
308
+
309
+ if err != nil {
310
+ log .Printf ("[CRITAL]%s modify PrivateDns record status failed, reason:%s\n " , logId , err .Error ())
311
+ return err
312
+ }
313
+ }
239
314
}
240
315
241
316
return resourceTencentCloudDPrivateDnsRecordRead (d , meta )
0 commit comments