@@ -76,6 +76,7 @@ func ResourceTencentCloudMqttInstance() *schema.Resource {
7676 "renew_flag" : {
7777 Type : schema .TypeInt ,
7878 Optional : true ,
79+ Computed : true ,
7980 Description : "Whether to enable auto-renewal (0: Disabled; 1: Enabled)." ,
8081 },
8182
@@ -105,6 +106,13 @@ func ResourceTencentCloudMqttInstance() *schema.Resource {
105106 Description : "Is the automatic registration certificate automatically activated. Default is false." ,
106107 },
107108
109+ "authorization_policy" : {
110+ Type : schema .TypeBool ,
111+ Optional : true ,
112+ Computed : true ,
113+ Description : "Authorization policy switch. Default is false." ,
114+ },
115+
108116 "force_delete" : {
109117 Type : schema .TypeBool ,
110118 Optional : true ,
@@ -226,27 +234,39 @@ func ResourceTencentCloudMqttInstanceCreate(d *schema.ResourceData, meta interfa
226234 return reqErr
227235 }
228236
229- // open automatic_activation
237+ var (
238+ isAutomaticActivation bool
239+ isAuthorizationPolicy bool
240+ )
241+
230242 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+ }
242245
243- return nil
244- })
246+ if v , ok := d .GetOkExists ("authorization_policy" ); ok {
247+ isAuthorizationPolicy = v .(bool )
248+ }
245249
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 ())
249262 }
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
250270 }
251271 }
252272
@@ -322,6 +342,10 @@ func ResourceTencentCloudMqttInstanceRead(d *schema.ResourceData, meta interface
322342 _ = d .Set ("automatic_activation" , respData .AutomaticActivation )
323343 }
324344
345+ if respData .AuthorizationPolicy != nil {
346+ _ = d .Set ("authorization_policy" , respData .AuthorizationPolicy )
347+ }
348+
325349 forceDelete := false
326350 if v , ok := d .GetOkExists ("force_delete" ); ok {
327351 forceDelete = v .(bool )
@@ -356,7 +380,7 @@ func ResourceTencentCloudMqttInstanceUpdate(d *schema.ResourceData, meta interfa
356380 }
357381
358382 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" }
360384 for _ , v := range mutableArgs {
361385 if d .HasChange (v ) {
362386 needChange = true
@@ -383,6 +407,10 @@ func ResourceTencentCloudMqttInstanceUpdate(d *schema.ResourceData, meta interfa
383407 request .AutomaticActivation = helper .Bool (v .(bool ))
384408 }
385409
410+ if v , ok := d .GetOkExists ("authorization_policy" ); ok {
411+ request .AuthorizationPolicy = helper .Bool (v .(bool ))
412+ }
413+
386414 reqErr := resource .Retry (tccommon .WriteRetryTimeout , func () * resource.RetryError {
387415 result , e := meta .(tccommon.ProviderMeta ).GetAPIV3Conn ().UseMqttV20240516Client ().ModifyInstanceWithContext (ctx , request )
388416 if e != nil {
0 commit comments