@@ -47,22 +47,29 @@ func ResourceTencentCloudPrivateDnsRecord() *schema.Resource {
4747 Description : "Record value, such as IP: 192.168.10.2, CNAME: cname.qcloud.com, and MX: mail.qcloud.com." ,
4848 },
4949 "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." ,
5354 },
5455 "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." ,
5959 },
6060 "ttl" : {
6161 Type : schema .TypeInt ,
6262 Optional : true ,
6363 Computed : true ,
6464 Description : "Record cache time. The smaller the value, the faster the record will take effect. Value range: 1~86400s." ,
6565 },
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+ },
6673 },
6774 }
6875}
@@ -130,14 +137,39 @@ func resourceTencentCloudDPrivateDnsRecordCreate(d *schema.ResourceData, meta in
130137 }
131138
132139 recordId := * response .Response .RecordId
140+ d .SetId (strings .Join ([]string {zoneId , recordId }, tccommon .FILED_SP ))
133141
134142 // wait
135143 _ , err = service .DescribePrivateDnsRecordById (ctx , zoneId , recordId )
136144 if err != nil {
137145 return err
138146 }
139147
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+ }
141173
142174 return resourceTencentCloudDPrivateDnsRecordRead (d , meta )
143175}
@@ -179,15 +211,24 @@ func resourceTencentCloudDPrivateDnsRecordRead(d *schema.ResourceData, meta inte
179211 _ = d .Set ("mx" , record .MX )
180212 _ = d .Set ("ttl" , record .TTL )
181213
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+
182222 return nil
183223}
184224
185225func resourceTencentCloudDPrivateDnsRecordUpdate (d * schema.ResourceData , meta interface {}) error {
186226 defer tccommon .LogElapsed ("resource.tencentcloud_private_dns_record.update" )()
187227
188228 var (
189- logId = tccommon .GetLogId (tccommon .ContextNil )
190- request = privatedns .NewModifyPrivateZoneRecordRequest ()
229+ logId = tccommon .GetLogId (tccommon .ContextNil )
230+ request = privatedns .NewModifyPrivateZoneRecordRequest ()
231+ needChange bool
191232 )
192233
193234 idSplit := strings .Split (d .Id (), tccommon .FILED_SP )
@@ -198,44 +239,78 @@ func resourceTencentCloudDPrivateDnsRecordUpdate(d *schema.ResourceData, meta in
198239 zoneId := idSplit [0 ]
199240 recordId := idSplit [1 ]
200241
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+ }
205248 }
206249
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+ }
210254
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+ }
214258
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+ }
218262
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+ }
222266
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+ }
226270
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 )))
231273 }
232274
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+ }
235282
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+ }
239314 }
240315
241316 return resourceTencentCloudDPrivateDnsRecordRead (d , meta )
0 commit comments