@@ -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,39 @@ 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
- 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
- }
243
+ isAutomaticActivation = v .(bool )
244
+ }
242
245
243
- return nil
244
- })
246
+ if v , ok := d .GetOkExists ("authorization_policy" ); ok {
247
+ isAuthorizationPolicy = v .(bool )
248
+ }
245
249
246
- if reqErr != nil {
247
- log .Printf ("[CRITAL]%s update mqtt failed, reason:%+v" , logId , reqErr )
248
- return reqErr
250
+ // open automatic_activation or authorization_policy
251
+ if isAutomaticActivation || isAuthorizationPolicy {
252
+ modifyRequest := mqttv20240516 .NewModifyInstanceRequest ()
253
+ modifyRequest .InstanceId = & instanceId
254
+ modifyRequest .AutomaticActivation = helper .Bool (isAutomaticActivation )
255
+ modifyRequest .AuthorizationPolicy = helper .Bool (isAuthorizationPolicy )
256
+ reqErr := resource .Retry (tccommon .WriteRetryTimeout , func () * resource.RetryError {
257
+ result , e := meta .(tccommon.ProviderMeta ).GetAPIV3Conn ().UseMqttV20240516Client ().ModifyInstanceWithContext (ctx , modifyRequest )
258
+ if e != nil {
259
+ return tccommon .RetryError (e )
260
+ } else {
261
+ log .Printf ("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n " , logId , modifyRequest .GetAction (), modifyRequest .ToJsonString (), result .ToJsonString ())
249
262
}
263
+
264
+ return nil
265
+ })
266
+
267
+ if reqErr != nil {
268
+ log .Printf ("[CRITAL]%s update mqtt failed, reason:%+v" , logId , reqErr )
269
+ return reqErr
250
270
}
251
271
}
252
272
@@ -322,6 +342,10 @@ func ResourceTencentCloudMqttInstanceRead(d *schema.ResourceData, meta interface
322
342
_ = d .Set ("automatic_activation" , respData .AutomaticActivation )
323
343
}
324
344
345
+ if respData .AuthorizationPolicy != nil {
346
+ _ = d .Set ("authorization_policy" , respData .AuthorizationPolicy )
347
+ }
348
+
325
349
forceDelete := false
326
350
if v , ok := d .GetOkExists ("force_delete" ); ok {
327
351
forceDelete = v .(bool )
@@ -356,7 +380,7 @@ func ResourceTencentCloudMqttInstanceUpdate(d *schema.ResourceData, meta interfa
356
380
}
357
381
358
382
needChange := false
359
- mutableArgs := []string {"name" , "remark" , "sku_code" , "device_certificate_provision_type" , "automatic_activation" }
383
+ mutableArgs := []string {"name" , "remark" , "sku_code" , "device_certificate_provision_type" , "automatic_activation" , "authorization_policy" }
360
384
for _ , v := range mutableArgs {
361
385
if d .HasChange (v ) {
362
386
needChange = true
@@ -383,6 +407,10 @@ func ResourceTencentCloudMqttInstanceUpdate(d *schema.ResourceData, meta interfa
383
407
request .AutomaticActivation = helper .Bool (v .(bool ))
384
408
}
385
409
410
+ if v , ok := d .GetOkExists ("authorization_policy" ); ok {
411
+ request .AuthorizationPolicy = helper .Bool (v .(bool ))
412
+ }
413
+
386
414
reqErr := resource .Retry (tccommon .WriteRetryTimeout , func () * resource.RetryError {
387
415
result , e := meta .(tccommon.ProviderMeta ).GetAPIV3Conn ().UseMqttV20240516Client ().ModifyInstanceWithContext (ctx , request )
388
416
if e != nil {
0 commit comments