Skip to content

Commit 9eb0aed

Browse files
committed
add
1 parent 860903d commit 9eb0aed

6 files changed

+195
-25
lines changed

tencentcloud/provider.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2262,10 +2262,11 @@ func Provider() *schema.Provider {
22622262
"tencentcloud_mqtt_instance_public_endpoint": mqtt.ResourceTencentCloudMqttInstancePublicEndpoint(),
22632263
"tencentcloud_mqtt_topic": mqtt.ResourceTencentCloudMqttTopic(),
22642264
"tencentcloud_mqtt_ca_certificate": mqtt.ResourceTencentCloudMqttCaCertificate(),
2265-
"tencentcloud_mqtt_user": mqtt.ResourceTencentCloudMqttUser(),
22662265
"tencentcloud_mqtt_device_certificate": mqtt.ResourceTencentCloudMqttDeviceCertificate(),
2266+
"tencentcloud_mqtt_user": mqtt.ResourceTencentCloudMqttUser(),
22672267
"tencentcloud_mqtt_jwt_authenticator": mqtt.ResourceTencentCloudMqttJwtAuthenticator(),
22682268
"tencentcloud_mqtt_jwks_authenticator": mqtt.ResourceTencentCloudMqttJwksAuthenticator(),
2269+
"tencentcloud_mqtt_http_authenticator": mqtt.ResourceTencentCloudMqttHttpAuthenticator(),
22692270
},
22702271

22712272
ConfigureFunc: providerConfigure,

tencentcloud/services/mqtt/resource_tc_mqtt_http_authenticator.go

Lines changed: 96 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package mqtt
22

33
import (
44
"context"
5+
"encoding/json"
56
"fmt"
67
"log"
78

@@ -19,6 +20,9 @@ func ResourceTencentCloudMqttHttpAuthenticator() *schema.Resource {
1920
Read: resourceTencentCloudMqttHttpAuthenticatorRead,
2021
Update: resourceTencentCloudMqttHttpAuthenticatorUpdate,
2122
Delete: resourceTencentCloudMqttHttpAuthenticatorDelete,
23+
Importer: &schema.ResourceImporter{
24+
State: schema.ImportStatePassthrough,
25+
},
2226
Schema: map[string]*schema.Schema{
2327
"instance_id": {
2428
Type: schema.TypeString,
@@ -41,7 +45,14 @@ func ResourceTencentCloudMqttHttpAuthenticator() *schema.Resource {
4145
"method": {
4246
Type: schema.TypeString,
4347
Optional: true,
44-
Description: "Network request method Get or Post, default Post.",
48+
Description: "Network request method GET or POST, default POST.",
49+
},
50+
51+
"status": {
52+
Type: schema.TypeString,
53+
Optional: true,
54+
Computed: true,
55+
Description: "Is the authenticator enabled: open enable; Close close.",
4556
},
4657

4758
"remark": {
@@ -133,6 +144,10 @@ func resourceTencentCloudMqttHttpAuthenticatorCreate(d *schema.ResourceData, met
133144
request.Method = helper.String(v.(string))
134145
}
135146

147+
if v, ok := d.GetOk("status"); ok {
148+
request.Status = helper.String(v.(string))
149+
}
150+
136151
if v, ok := d.GetOk("remark"); ok {
137152
request.Remark = helper.String(v.(string))
138153
}
@@ -224,6 +239,82 @@ func resourceTencentCloudMqttHttpAuthenticatorRead(d *schema.ResourceData, meta
224239
return nil
225240
}
226241

242+
_ = d.Set("instance_id", instanceId)
243+
244+
if respData.Config != nil {
245+
var configMap map[string]interface{}
246+
e := json.Unmarshal([]byte(*respData.Config), &configMap)
247+
if e != nil {
248+
return fmt.Errorf("Failed to parse config content: %s", e.Error())
249+
}
250+
251+
if v, ok := configMap["endpoint"].(string); ok && v != "" {
252+
_ = d.Set("endpoint", v)
253+
}
254+
255+
if v, ok := configMap["concurrency"].(float64); ok {
256+
_ = d.Set("concurrency", int(v))
257+
}
258+
259+
if v, ok := configMap["method"].(string); ok && v != "" {
260+
_ = d.Set("method", v)
261+
}
262+
263+
if v, ok := configMap["connectTimeout"].(float64); ok {
264+
_ = d.Set("connect_timeout", int(v))
265+
}
266+
267+
if v, ok := configMap["readTimeout"].(float64); ok {
268+
_ = d.Set("read_timeout", int(v))
269+
}
270+
271+
if v, ok := configMap["headers"].([]interface{}); ok {
272+
tmpList := make([]map[string]interface{}, 0)
273+
for _, item := range v {
274+
bodyMap := item.(map[string]interface{})
275+
dMap := map[string]interface{}{}
276+
if v, ok := bodyMap["key"].(string); ok && v != "" {
277+
dMap["key"] = v
278+
}
279+
280+
if v, ok := bodyMap["value"].(string); ok && v != "" {
281+
dMap["value"] = v
282+
}
283+
284+
tmpList = append(tmpList, dMap)
285+
}
286+
287+
_ = d.Set("header", tmpList)
288+
}
289+
290+
if v, ok := configMap["body"].([]interface{}); ok {
291+
tmpList := make([]map[string]interface{}, 0)
292+
for _, item := range v {
293+
bodyMap := item.(map[string]interface{})
294+
dMap := map[string]interface{}{}
295+
if v, ok := bodyMap["key"].(string); ok && v != "" {
296+
dMap["key"] = v
297+
}
298+
299+
if v, ok := bodyMap["value"].(string); ok && v != "" {
300+
dMap["value"] = v
301+
}
302+
303+
tmpList = append(tmpList, dMap)
304+
}
305+
306+
_ = d.Set("body", tmpList)
307+
}
308+
}
309+
310+
if respData.Status != nil {
311+
_ = d.Set("status", respData.Status)
312+
}
313+
314+
if respData.Remark != nil {
315+
_ = d.Set("remark", respData.Remark)
316+
}
317+
227318
return nil
228319
}
229320

@@ -264,6 +355,10 @@ func resourceTencentCloudMqttHttpAuthenticatorUpdate(d *schema.ResourceData, met
264355
request.Method = helper.String(v.(string))
265356
}
266357

358+
if v, ok := d.GetOk("status"); ok {
359+
request.Status = helper.String(v.(string))
360+
}
361+
267362
if v, ok := d.GetOk("header"); ok {
268363
for _, item := range v.([]interface{}) {
269364
headerMap := item.(map[string]interface{})
Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,33 @@
1-
Provides a resource to create a mqtt mqtt_http_authenticator
1+
Provides a resource to create a MQTT http authenticator
22

33
Example Usage
44

55
```hcl
6-
resource "tencentcloud_mqtt_http_authenticator" "mqtt_http_authenticator" {
7-
header = {
6+
resource "tencentcloud_mqtt_http_authenticator" "example" {
7+
instance_id = "mqtt-zxjwkr98"
8+
endpoint = "https://example.com"
9+
concurrency = 8
10+
method = "POST"
11+
status = "open"
12+
remark = "Remark."
13+
connect_timeout = 10
14+
read_timeout = 10
15+
header {
16+
key = "Content-type"
17+
value = "application/json"
818
}
9-
body = {
19+
20+
body {
21+
key = "bodyKey"
22+
value = "bodyValue"
1023
}
1124
}
1225
```
1326

1427
Import
1528

16-
mqtt mqtt_http_authenticator can be imported using the id, e.g.
29+
MQTT http authenticator can be imported using the id, e.g.
1730

1831
```
19-
terraform import tencentcloud_mqtt_http_authenticator.mqtt_http_authenticator mqtt_http_authenticator_id
32+
terraform import tencentcloud_mqtt_http_authenticator.example mqtt-zxjwkr98
2033
```

tencentcloud/services/mqtt/resource_tc_mqtt_http_authenticator_test.go

Lines changed: 72 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,84 @@ func TestAccTencentCloudMqttHttpAuthenticatorResource_basic(t *testing.T) {
1515
tcacctest.AccPreCheck(t)
1616
},
1717
Providers: tcacctest.AccProviders,
18-
Steps: []resource.TestStep{{
19-
Config: testAccMqttHttpAuthenticator,
20-
Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_mqtt_http_authenticator.mqtt_http_authenticator", "id")),
21-
}, {
22-
ResourceName: "tencentcloud_mqtt_http_authenticator.mqtt_http_authenticator",
23-
ImportState: true,
24-
ImportStateVerify: true,
25-
}},
18+
Steps: []resource.TestStep{
19+
{
20+
Config: testAccMqttHttpAuthenticator,
21+
Check: resource.ComposeTestCheckFunc(
22+
resource.TestCheckResourceAttrSet("tencentcloud_mqtt_http_authenticator.example", "id"),
23+
resource.TestCheckResourceAttrSet("tencentcloud_mqtt_http_authenticator.example", "instance_id"),
24+
resource.TestCheckResourceAttrSet("tencentcloud_mqtt_http_authenticator.example", "endpoint"),
25+
resource.TestCheckResourceAttrSet("tencentcloud_mqtt_http_authenticator.example", "concurrency"),
26+
resource.TestCheckResourceAttrSet("tencentcloud_mqtt_http_authenticator.example", "method"),
27+
resource.TestCheckResourceAttrSet("tencentcloud_mqtt_http_authenticator.example", "status"),
28+
resource.TestCheckResourceAttrSet("tencentcloud_mqtt_http_authenticator.example", "remark"),
29+
resource.TestCheckResourceAttrSet("tencentcloud_mqtt_http_authenticator.example", "connect_timeout"),
30+
resource.TestCheckResourceAttrSet("tencentcloud_mqtt_http_authenticator.example", "read_timeout"),
31+
),
32+
},
33+
{
34+
Config: testAccMqttHttpAuthenticatorUpdate,
35+
Check: resource.ComposeTestCheckFunc(
36+
resource.TestCheckResourceAttrSet("tencentcloud_mqtt_http_authenticator.example", "id"),
37+
resource.TestCheckResourceAttrSet("tencentcloud_mqtt_http_authenticator.example", "instance_id"),
38+
resource.TestCheckResourceAttrSet("tencentcloud_mqtt_http_authenticator.example", "endpoint"),
39+
resource.TestCheckResourceAttrSet("tencentcloud_mqtt_http_authenticator.example", "concurrency"),
40+
resource.TestCheckResourceAttrSet("tencentcloud_mqtt_http_authenticator.example", "method"),
41+
resource.TestCheckResourceAttrSet("tencentcloud_mqtt_http_authenticator.example", "status"),
42+
resource.TestCheckResourceAttrSet("tencentcloud_mqtt_http_authenticator.example", "remark"),
43+
resource.TestCheckResourceAttrSet("tencentcloud_mqtt_http_authenticator.example", "connect_timeout"),
44+
resource.TestCheckResourceAttrSet("tencentcloud_mqtt_http_authenticator.example", "read_timeout"),
45+
),
46+
},
47+
{
48+
ResourceName: "tencentcloud_mqtt_http_authenticator.example",
49+
ImportState: true,
50+
ImportStateVerify: true,
51+
},
52+
},
2653
})
2754
}
2855

2956
const testAccMqttHttpAuthenticator = `
57+
resource "tencentcloud_mqtt_http_authenticator" "example" {
58+
instance_id = "mqtt-zxjwkr98"
59+
endpoint = "https://example.com"
60+
concurrency = 8
61+
method = "POST"
62+
status = "open"
63+
remark = "Remark."
64+
connect_timeout = 10
65+
read_timeout = 10
66+
header {
67+
key = "Content-type"
68+
value = "application/json"
69+
}
3070
31-
resource "tencentcloud_mqtt_http_authenticator" "mqtt_http_authenticator" {
32-
header = {
71+
body {
72+
key = "bodyKey"
73+
value = "bodyValue"
3374
}
34-
body = {
75+
}
76+
`
77+
78+
const testAccMqttHttpAuthenticatorUpdate = `
79+
resource "tencentcloud_mqtt_http_authenticator" "example" {
80+
instance_id = "mqtt-zxjwkr98"
81+
endpoint = "https://example.com"
82+
concurrency = 8
83+
method = "GET"
84+
status = "close"
85+
remark = "Remark update."
86+
connect_timeout = 10
87+
read_timeout = 10
88+
header {
89+
key = "Content-type"
90+
value = "application/json"
91+
}
92+
93+
body {
94+
key = "bodyKey"
95+
value = "bodyValue"
3596
}
3697
}
3798
`

tencentcloud/services/mqtt/resource_tc_mqtt_jwks_authenticator.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ func ResourceTencentCloudMqttJwksAuthenticator() *schema.Resource {
2020
Read: resourceTencentCloudMqttJwksAuthenticatorRead,
2121
Update: resourceTencentCloudMqttJwksAuthenticatorUpdate,
2222
Delete: resourceTencentCloudMqttJwksAuthenticatorDelete,
23+
Importer: &schema.ResourceImporter{
24+
State: schema.ImportStatePassthrough,
25+
},
2326
Schema: map[string]*schema.Schema{
2427
"instance_id": {
2528
Type: schema.TypeString,
@@ -157,8 +160,8 @@ func resourceTencentCloudMqttJwksAuthenticatorRead(d *schema.ResourceData, meta
157160
_ = d.Set("endpoint", v)
158161
}
159162

160-
if v, ok := configMap["refresh_interval"].(int); ok {
161-
_ = d.Set("refresh_interval", v)
163+
if v, ok := configMap["refreshInterval"].(float64); ok {
164+
_ = d.Set("refresh_interval", int(v))
162165
}
163166

164167
if v, ok := configMap["text"].(string); ok && v != "" {
@@ -210,6 +213,7 @@ func resourceTencentCloudMqttJwksAuthenticatorUpdate(d *schema.ResourceData, met
210213
request.Remark = helper.String(v.(string))
211214
}
212215

216+
request.Status = helper.String("open")
213217
reqErr := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
214218
result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseMqttV20240516Client().ModifyJWKSAuthenticatorWithContext(ctx, request)
215219
if e != nil {

tencentcloud/services/mqtt/resource_tc_mqtt_jwt_authenticator.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,6 @@ func resourceTencentCloudMqttJwtAuthenticatorCreate(d *schema.ResourceData, meta
9696
request.PublicKey = helper.String(v.(string))
9797
}
9898

99-
if v, ok := d.GetOk("status"); ok {
100-
request.Status = helper.String(v.(string))
101-
}
102-
10399
if v, ok := d.GetOk("remark"); ok {
104100
request.Remark = helper.String(v.(string))
105101
}

0 commit comments

Comments
 (0)