Skip to content

Commit 5065d2c

Browse files
committed
add
1 parent e3318ff commit 5065d2c

16 files changed

+1266
-0
lines changed

tencentcloud/provider.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,6 +1238,9 @@ func Provider() *schema.Provider {
12381238
"tencentcloud_cdwpg_log": cdwpg.DataSourceTencentCloudCdwpgLog(),
12391239
"tencentcloud_cdwpg_nodes": cdwpg.DataSourceTencentCloudCdwpgNodes(),
12401240
"tencentcloud_mqtt_registration_code": mqtt.DataSourceTencentCloudMqttRegistrationCode(),
1241+
"tencentcloud_mqtt_instances": mqtt.DataSourceTencentCloudMqttInstances(),
1242+
"tencentcloud_mqtt_instance_detail": mqtt.DataSourceTencentCloudMqttInstanceDetail(),
1243+
"tencentcloud_mqtt_topics": mqtt.DataSourceTencentCloudMqttTopics(),
12411244
},
12421245

12431246
ResourcesMap: map[string]*schema.Resource{

tencentcloud/provider.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2319,6 +2319,9 @@ tencentcloud_tcss_image_registry
23192319
TDMQ for MQTT(MQTT)
23202320
Data Source
23212321
tencentcloud_mqtt_registration_code
2322+
tencentcloud_mqtt_instances
2323+
tencentcloud_mqtt_instance_detail
2324+
tencentcloud_mqtt_topics
23222325
Resource
23232326
tencentcloud_mqtt_instance
23242327
tencentcloud_mqtt_instance_public_endpoint
Lines changed: 309 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,309 @@
1+
package mqtt
2+
3+
import (
4+
"context"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
8+
mqttv20240516 "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/mqtt/v20240516"
9+
10+
tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common"
11+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
12+
)
13+
14+
func DataSourceTencentCloudMqttInstanceDetail() *schema.Resource {
15+
return &schema.Resource{
16+
Read: dataSourceTencentCloudMqttInstanceDetailRead,
17+
Schema: map[string]*schema.Schema{
18+
"instance_id": {
19+
Type: schema.TypeString,
20+
Required: true,
21+
Description: "Instance ID.",
22+
},
23+
24+
// computed
25+
"instance_type": {
26+
Type: schema.TypeString,
27+
Computed: true,
28+
Description: "Instance ID.",
29+
},
30+
31+
"instance_name": {
32+
Type: schema.TypeString,
33+
Computed: true,
34+
Description: "Instance type. BASIC- Basic Edition; PRO- professional edition; PLATINUM- Platinum version.",
35+
},
36+
37+
"topic_num": {
38+
Type: schema.TypeInt,
39+
Computed: true,
40+
Description: "Topic num.",
41+
},
42+
43+
"topic_num_limit": {
44+
Type: schema.TypeInt,
45+
Computed: true,
46+
Description: "Maximum number of instance topics.",
47+
},
48+
49+
"tps_limit": {
50+
Type: schema.TypeInt,
51+
Computed: true,
52+
Description: "Elastic TPS current limit value.",
53+
},
54+
55+
"created_time": {
56+
Type: schema.TypeInt,
57+
Computed: true,
58+
Description: "Creation time, millisecond timestamp.",
59+
},
60+
61+
"remark": {
62+
Type: schema.TypeString,
63+
Computed: true,
64+
Description: "Remark.",
65+
},
66+
67+
"instance_status": {
68+
Type: schema.TypeString,
69+
Computed: true,
70+
Description: "Instance status. RUNNING- In operation; MAINTAINING- Under Maintenance; ABNORMAL- abnormal; OVERDUE- Arrears of fees; DESTROYED- Deleted; CREATING- Creating in progress; MODIFYING- In the process of transformation; CREATE_FAILURE- Creation failed; MODIFY_FAILURE- Transformation failed; DELETING- deleting.",
71+
},
72+
73+
"sku_code": {
74+
Type: schema.TypeString,
75+
Computed: true,
76+
Description: "Product specifications.",
77+
},
78+
79+
"max_subscription_per_client": {
80+
Type: schema.TypeInt,
81+
Computed: true,
82+
Description: "Maximum number of subscriptions per client.",
83+
},
84+
85+
"authorization_policy_limit": {
86+
Type: schema.TypeInt,
87+
Computed: true,
88+
Description: "Limit on the number of authorization rules.",
89+
},
90+
91+
"client_num_limit": {
92+
Type: schema.TypeInt,
93+
Computed: true,
94+
Description: "Number of client connections online.",
95+
},
96+
97+
"device_certificate_provision_type": {
98+
Type: schema.TypeString,
99+
Computed: true,
100+
Description: "Client certificate registration method: JITP: Automatic Registration; API: Manually register through API.",
101+
},
102+
103+
"automatic_activation": {
104+
Type: schema.TypeBool,
105+
Computed: true,
106+
Description: "Is it automatically activated when registering device certificates automatically.",
107+
},
108+
109+
"renew_flag": {
110+
Type: schema.TypeInt,
111+
Computed: true,
112+
Description: "Whether to renew automatically. Only the annual and monthly package cluster is effective. 1: Automatic renewal; 0: Non automatic renewal.",
113+
},
114+
115+
"pay_mode": {
116+
Type: schema.TypeString,
117+
Computed: true,
118+
Description: "Billing mode, POSTPAID, pay as you go PREPAID, annual and monthly package.",
119+
},
120+
121+
"expiry_time": {
122+
Type: schema.TypeInt,
123+
Computed: true,
124+
Description: "Expiration time, millisecond level timestamp.",
125+
},
126+
127+
"destroy_time": {
128+
Type: schema.TypeInt,
129+
Computed: true,
130+
Description: "Pre destruction time, millisecond timestamp.",
131+
},
132+
133+
"x509_mode": {
134+
Type: schema.TypeString,
135+
Computed: true,
136+
Description: "TLS, Unidirectional authentication mTLS, bidirectional authentication BYOC; One machine, one certificate.",
137+
},
138+
139+
"max_ca_num": {
140+
Type: schema.TypeInt,
141+
Computed: true,
142+
Description: "Maximum Ca quota.",
143+
},
144+
145+
"registration_code": {
146+
Type: schema.TypeString,
147+
Computed: true,
148+
Description: "Certificate registration code.",
149+
},
150+
151+
"max_subscription": {
152+
Type: schema.TypeInt,
153+
Computed: true,
154+
Description: "Maximum number of subscriptions in the cluster.",
155+
},
156+
157+
"authorization_policy": {
158+
Type: schema.TypeBool,
159+
Computed: true,
160+
Description: "Authorization Policy Switch.",
161+
},
162+
163+
"result_output_file": {
164+
Type: schema.TypeString,
165+
Optional: true,
166+
Description: "Used to save results.",
167+
},
168+
},
169+
}
170+
}
171+
172+
func dataSourceTencentCloudMqttInstanceDetailRead(d *schema.ResourceData, meta interface{}) error {
173+
defer tccommon.LogElapsed("data_source.tencentcloud_mqtt_instance_detail.read")()
174+
defer tccommon.InconsistentCheck(d, meta)()
175+
176+
var (
177+
logId = tccommon.GetLogId(nil)
178+
ctx = tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta)
179+
service = MqttService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
180+
instanceId string
181+
)
182+
183+
paramMap := make(map[string]interface{})
184+
if v, ok := d.GetOk("instance_id"); ok {
185+
paramMap["InstanceId"] = helper.String(v.(string))
186+
instanceId = v.(string)
187+
}
188+
189+
var respData *mqttv20240516.DescribeInstanceResponseParams
190+
reqErr := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError {
191+
result, e := service.DescribeMqttInstanceDetailByFilter(ctx, paramMap)
192+
if e != nil {
193+
return tccommon.RetryError(e)
194+
}
195+
196+
respData = result
197+
return nil
198+
})
199+
200+
if reqErr != nil {
201+
return reqErr
202+
}
203+
204+
if respData.InstanceType != nil {
205+
_ = d.Set("instance_type", respData.InstanceType)
206+
}
207+
208+
if respData.InstanceId != nil {
209+
_ = d.Set("instance_id", respData.InstanceId)
210+
}
211+
212+
if respData.InstanceName != nil {
213+
_ = d.Set("instance_name", respData.InstanceName)
214+
}
215+
216+
if respData.TopicNum != nil {
217+
_ = d.Set("topic_num", respData.TopicNum)
218+
}
219+
220+
if respData.TopicNumLimit != nil {
221+
_ = d.Set("topic_num_limit", respData.TopicNumLimit)
222+
}
223+
224+
if respData.TpsLimit != nil {
225+
_ = d.Set("tps_limit", respData.TpsLimit)
226+
}
227+
228+
if respData.CreatedTime != nil {
229+
_ = d.Set("created_time", respData.CreatedTime)
230+
}
231+
232+
if respData.Remark != nil {
233+
_ = d.Set("remark", respData.Remark)
234+
}
235+
236+
if respData.InstanceStatus != nil {
237+
_ = d.Set("instance_status", respData.InstanceStatus)
238+
}
239+
240+
if respData.SkuCode != nil {
241+
_ = d.Set("sku_code", respData.SkuCode)
242+
}
243+
244+
if respData.MaxSubscriptionPerClient != nil {
245+
_ = d.Set("max_subscription_per_client", respData.MaxSubscriptionPerClient)
246+
}
247+
248+
if respData.AuthorizationPolicyLimit != nil {
249+
_ = d.Set("authorization_policy_limit", respData.AuthorizationPolicyLimit)
250+
}
251+
252+
if respData.ClientNumLimit != nil {
253+
_ = d.Set("client_num_limit", respData.ClientNumLimit)
254+
}
255+
256+
if respData.DeviceCertificateProvisionType != nil {
257+
_ = d.Set("device_certificate_provision_type", respData.DeviceCertificateProvisionType)
258+
}
259+
260+
if respData.AutomaticActivation != nil {
261+
_ = d.Set("automatic_activation", respData.AutomaticActivation)
262+
}
263+
264+
if respData.RenewFlag != nil {
265+
_ = d.Set("renew_flag", respData.RenewFlag)
266+
}
267+
268+
if respData.PayMode != nil {
269+
_ = d.Set("pay_mode", respData.PayMode)
270+
}
271+
272+
if respData.ExpiryTime != nil {
273+
_ = d.Set("expiry_time", respData.ExpiryTime)
274+
}
275+
276+
if respData.DestroyTime != nil {
277+
_ = d.Set("destroy_time", respData.DestroyTime)
278+
}
279+
280+
if respData.X509Mode != nil {
281+
_ = d.Set("x509_mode", respData.X509Mode)
282+
}
283+
284+
if respData.MaxCaNum != nil {
285+
_ = d.Set("max_ca_num", respData.MaxCaNum)
286+
}
287+
288+
if respData.RegistrationCode != nil {
289+
_ = d.Set("registration_code", respData.RegistrationCode)
290+
}
291+
292+
if respData.MaxSubscription != nil {
293+
_ = d.Set("max_subscription", respData.MaxSubscription)
294+
}
295+
296+
if respData.AuthorizationPolicy != nil {
297+
_ = d.Set("authorization_policy", respData.AuthorizationPolicy)
298+
}
299+
300+
d.SetId(instanceId)
301+
output, ok := d.GetOk("result_output_file")
302+
if ok && output.(string) != "" {
303+
if e := tccommon.WriteToFile(output.(string), d); e != nil {
304+
return e
305+
}
306+
}
307+
308+
return nil
309+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Use this data source to query detailed information of MQTT instance detail
2+
3+
Example Usage
4+
5+
```hcl
6+
data "tencentcloud_mqtt_instance_detail" "example" {
7+
instance_id = "mqtt-kngmpg9p"
8+
}
9+
```
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package mqtt_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
8+
tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest"
9+
)
10+
11+
func TestAccTencentCloudMqttInstanceDetailDataSource_basic(t *testing.T) {
12+
t.Parallel()
13+
resource.Test(t, resource.TestCase{
14+
PreCheck: func() {
15+
tcacctest.AccPreCheck(t)
16+
},
17+
Providers: tcacctest.AccProviders,
18+
Steps: []resource.TestStep{{
19+
Config: testAccMqttInstanceDetailDataSource,
20+
Check: resource.ComposeTestCheckFunc(
21+
resource.TestCheckResourceAttrSet("data.tencentcloud_mqtt_instance_detail.example", "id"),
22+
resource.TestCheckResourceAttrSet("data.tencentcloud_mqtt_instance_detail.example", "instance_id"),
23+
),
24+
}},
25+
})
26+
}
27+
28+
const testAccMqttInstanceDetailDataSource = `
29+
data "tencentcloud_mqtt_instance_detail" "example" {
30+
instance_id = "mqtt-kngmpg9p"
31+
}
32+
`

0 commit comments

Comments
 (0)