Skip to content

Commit 7edbdde

Browse files
authored
fix(mqtt): [124504305] tencentcloud_mqtt_instance support authorization_policy (#3399)
* add * add * add
1 parent 859580c commit 7edbdde

File tree

4 files changed

+52
-18
lines changed

4 files changed

+52
-18
lines changed

.changelog/3399.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource/tencentcloud_mqtt_instance: support `authorization_policy`
3+
```

tencentcloud/services/mqtt/resource_tc_mqtt_instance.go

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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 {

tencentcloud/services/mqtt/resource_tc_mqtt_instance.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ resource "tencentcloud_mqtt_instance" "example" {
7878
renew_flag = 1
7979
force_delete = false
8080
automatic_activation = true
81+
authorization_policy = true
8182
tags = {
8283
createBy = "Terraform"
8384
}

website/docs/r/mqtt_instance.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ resource "tencentcloud_mqtt_instance" "example" {
8989
renew_flag = 1
9090
force_delete = false
9191
automatic_activation = true
92+
authorization_policy = true
9293
tags = {
9394
createBy = "Terraform"
9495
}
@@ -102,6 +103,7 @@ The following arguments are supported:
102103
* `instance_type` - (Required, String) Instance type. PRO for Professional Edition; PLATINUM for Platinum Edition.
103104
* `name` - (Required, String) Instance name.
104105
* `sku_code` - (Required, String) Product SKU, available SKUs can be queried via the DescribeProductSKUList API.
106+
* `authorization_policy` - (Optional, Bool) Authorization policy switch. Default is false.
105107
* `automatic_activation` - (Optional, Bool) Is the automatic registration certificate automatically activated. Default is false.
106108
* `force_delete` - (Optional, Bool) Indicate whether to force delete the instance. Default is `false`. If set true, the instance will be permanently deleted instead of being moved into the recycle bin. Note: only works for `PREPAID` instance.
107109
* `pay_mode` - (Optional, Int) Payment mode (0: Postpaid; 1: Prepaid).

0 commit comments

Comments
 (0)