@@ -76,6 +76,7 @@ func ResourceTencentCloudMqttInstance() *schema.Resource {
76
76
"renew_flag" : {
77
77
Type : schema .TypeInt ,
78
78
Optional : true ,
79
+ Computed : true ,
79
80
Description : "Whether to enable auto-renewal (0: Disabled; 1: Enabled)." ,
80
81
},
81
82
@@ -105,6 +106,13 @@ func ResourceTencentCloudMqttInstance() *schema.Resource {
105
106
Description : "Is the automatic registration certificate automatically activated. Default is false." ,
106
107
},
107
108
109
+ "authorization_policy" : {
110
+ Type : schema .TypeBool ,
111
+ Optional : true ,
112
+ Computed : true ,
113
+ Description : "Authorization policy switch. Default is false." ,
114
+ },
115
+
108
116
"force_delete" : {
109
117
Type : schema .TypeBool ,
110
118
Optional : true ,
@@ -226,27 +234,43 @@ func ResourceTencentCloudMqttInstanceCreate(d *schema.ResourceData, meta interfa
226
234
return reqErr
227
235
}
228
236
229
- // open automatic_activation
237
+ var (
238
+ isAutomaticActivation bool
239
+ isAuthorizationPolicy bool
240
+ )
241
+
230
242
if v , ok := d .GetOkExists ("automatic_activation" ); ok {
231
243
if v .(bool ) {
232
- modifyRequest := mqttv20240516 .NewModifyInstanceRequest ()
233
- modifyRequest .InstanceId = & instanceId
234
- modifyRequest .AutomaticActivation = helper .Bool (v .(bool ))
235
- reqErr := resource .Retry (tccommon .WriteRetryTimeout , func () * resource.RetryError {
236
- result , e := meta .(tccommon.ProviderMeta ).GetAPIV3Conn ().UseMqttV20240516Client ().ModifyInstanceWithContext (ctx , modifyRequest )
237
- if e != nil {
238
- return tccommon .RetryError (e )
239
- } else {
240
- log .Printf ("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n " , logId , modifyRequest .GetAction (), modifyRequest .ToJsonString (), result .ToJsonString ())
241
- }
244
+ isAutomaticActivation = true
245
+ }
246
+ }
242
247
243
- return nil
244
- })
248
+ if v , ok := d .GetOkExists ("authorization_policy" ); ok {
249
+ if v .(bool ) {
250
+ isAuthorizationPolicy = true
251
+ }
252
+ }
245
253
246
- if reqErr != nil {
247
- log .Printf ("[CRITAL]%s update mqtt failed, reason:%+v" , logId , reqErr )
248
- return reqErr
254
+ // open automatic_activation or authorization_policy
255
+ if isAutomaticActivation || isAuthorizationPolicy {
256
+ modifyRequest := mqttv20240516 .NewModifyInstanceRequest ()
257
+ modifyRequest .InstanceId = & instanceId
258
+ modifyRequest .AutomaticActivation = helper .Bool (isAutomaticActivation )
259
+ modifyRequest .AuthorizationPolicy = helper .Bool (isAuthorizationPolicy )
260
+ reqErr := resource .Retry (tccommon .WriteRetryTimeout , func () * resource.RetryError {
261
+ result , e := meta .(tccommon.ProviderMeta ).GetAPIV3Conn ().UseMqttV20240516Client ().ModifyInstanceWithContext (ctx , modifyRequest )
262
+ if e != nil {
263
+ return tccommon .RetryError (e )
264
+ } else {
265
+ log .Printf ("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n " , logId , modifyRequest .GetAction (), modifyRequest .ToJsonString (), result .ToJsonString ())
249
266
}
267
+
268
+ return nil
269
+ })
270
+
271
+ if reqErr != nil {
272
+ log .Printf ("[CRITAL]%s update mqtt failed, reason:%+v" , logId , reqErr )
273
+ return reqErr
250
274
}
251
275
}
252
276
@@ -322,6 +346,10 @@ func ResourceTencentCloudMqttInstanceRead(d *schema.ResourceData, meta interface
322
346
_ = d .Set ("automatic_activation" , respData .AutomaticActivation )
323
347
}
324
348
349
+ if respData .AuthorizationPolicy != nil {
350
+ _ = d .Set ("authorization_policy" , respData .AuthorizationPolicy )
351
+ }
352
+
325
353
forceDelete := false
326
354
if v , ok := d .GetOkExists ("force_delete" ); ok {
327
355
forceDelete = v .(bool )
@@ -356,7 +384,7 @@ func ResourceTencentCloudMqttInstanceUpdate(d *schema.ResourceData, meta interfa
356
384
}
357
385
358
386
needChange := false
359
- mutableArgs := []string {"name" , "remark" , "sku_code" , "device_certificate_provision_type" , "automatic_activation" }
387
+ mutableArgs := []string {"name" , "remark" , "sku_code" , "device_certificate_provision_type" , "automatic_activation" , "authorization_policy" }
360
388
for _ , v := range mutableArgs {
361
389
if d .HasChange (v ) {
362
390
needChange = true
@@ -383,6 +411,10 @@ func ResourceTencentCloudMqttInstanceUpdate(d *schema.ResourceData, meta interfa
383
411
request .AutomaticActivation = helper .Bool (v .(bool ))
384
412
}
385
413
414
+ if v , ok := d .GetOkExists ("authorization_policy" ); ok {
415
+ request .AuthorizationPolicy = helper .Bool (v .(bool ))
416
+ }
417
+
386
418
reqErr := resource .Retry (tccommon .WriteRetryTimeout , func () * resource.RetryError {
387
419
result , e := meta .(tccommon.ProviderMeta ).GetAPIV3Conn ().UseMqttV20240516Client ().ModifyInstanceWithContext (ctx , request )
388
420
if e != nil {
0 commit comments