Skip to content

Commit 74f0c15

Browse files
authored
feat(teo): [124818645] add new data source (#3416)
* add * add
1 parent 72a716b commit 74f0c15

File tree

10 files changed

+997
-0
lines changed

10 files changed

+997
-0
lines changed

.changelog/3416.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:new-data-source
2+
tencentcloud_teo_plans
3+
```

tencentcloud/provider.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,7 @@ func Provider() *schema.Provider {
903903
"tencentcloud_teo_zone_available_plans": teo.DataSourceTencentCloudTeoZoneAvailablePlans(),
904904
"tencentcloud_teo_rule_engine_settings": teo.DataSourceTencentCloudTeoRuleEngineSettings(),
905905
"tencentcloud_teo_zones": teo.DataSourceTencentCloudTeoZones(),
906+
"tencentcloud_teo_plans": teo.DataSourceTencentCloudTeoPlans(),
906907
"tencentcloud_sts_caller_identity": sts.DataSourceTencentCloudStsCallerIdentity(),
907908
"tencentcloud_dcdb_instances": dcdb.DataSourceTencentCloudDcdbInstances(),
908909
"tencentcloud_dcdb_accounts": dcdb.DataSourceTencentCloudDcdbAccounts(),
@@ -1874,6 +1875,7 @@ func Provider() *schema.Provider {
18741875
"tencentcloud_teo_security_policy_config": teo.ResourceTencentCloudTeoSecurityPolicyConfig(),
18751876
"tencentcloud_teo_dns_record": teo.ResourceTencentCloudTeoDnsRecord(),
18761877
"tencentcloud_teo_bind_security_template": teo.ResourceTencentCloudTeoBindSecurityTemplate(),
1878+
"tencentcloud_teo_plan": teo.ResourceTencentCloudTeoPlan(),
18771879
"tencentcloud_tcm_mesh": tcm.ResourceTencentCloudTcmMesh(),
18781880
"tencentcloud_tcm_cluster_attachment": tcm.ResourceTencentCloudTcmClusterAttachment(),
18791881
"tencentcloud_tcm_prometheus_attachment": tcm.ResourceTencentCloudTcmPrometheusAttachment(),

tencentcloud/provider.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,6 +1488,7 @@ Data Source
14881488
tencentcloud_teo_zone_available_plans
14891489
tencentcloud_teo_rule_engine_settings
14901490
tencentcloud_teo_zones
1491+
tencentcloud_teo_plans
14911492

14921493
Resource
14931494
tencentcloud_teo_zone
Lines changed: 357 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,357 @@
1+
package teo
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+
teo "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo/v20220901"
9+
tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common"
10+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
11+
)
12+
13+
func DataSourceTencentCloudTeoPlans() *schema.Resource {
14+
return &schema.Resource{
15+
Read: DataSourceTencentCloudTeoPlansRead,
16+
Schema: map[string]*schema.Schema{
17+
"filters": {
18+
Optional: true,
19+
Type: schema.TypeList,
20+
Description: "Filter conditions, the upper limit of Filters. Values is 20. The detailed filtering conditions are as follows: <li>plan-type<br>Filter according to [<strong>Package Type</strong>]. <br>Optional types are: <br>plan-trial: Trial Package; <br>plan-personal: Personal Package; <br>plan-basic: Basic Package; <br>plan-standard: Standard Package; <br>plan-enterprise: Enterprise Package. </li><li>plan-id<br>Filter according to [<strong>Package ID</strong>]. The package ID is in the form of: edgeone-268z103ob0sx.</li><li>area<br>Filter according to [<strong>Package Acceleration Region</strong>]. </li>Service area, optional types are: <br>mainland: Mainland China; <br>overseas: Global (excluding Mainland China); <br>global: Global (including Mainland China).<br><li>status<br>Filter by [<strong>Package Status</strong>].<br>The available statuses are:<br>normal: normal status;<br>expiring-soon: about to expire;<br>expired: expired;<br>isolated: isolated.</li>.",
21+
Elem: &schema.Resource{
22+
Schema: map[string]*schema.Schema{
23+
"name": {
24+
Type: schema.TypeString,
25+
Required: true,
26+
Description: "Filter name.",
27+
},
28+
"values": {
29+
Type: schema.TypeSet,
30+
Elem: &schema.Schema{Type: schema.TypeString},
31+
Required: true,
32+
Description: "Filter value.",
33+
},
34+
},
35+
},
36+
},
37+
38+
"order": {
39+
Optional: true,
40+
Type: schema.TypeString,
41+
Description: "Sorting field, the values are: <li> enable-time: effective time; </li><li> expire-time: expiration time. </li> If not filled in, the default value enable-time will be used.",
42+
},
43+
44+
"direction": {
45+
Optional: true,
46+
Type: schema.TypeString,
47+
Description: "Sorting direction, the possible values are: <li>asc: sort from small to large; </li><li>desc: sort from large to small. </li>If not filled in, the default value desc will be used.",
48+
},
49+
50+
// computed
51+
"plans": {
52+
Computed: true,
53+
Type: schema.TypeList,
54+
Description: "Plan list.",
55+
Elem: &schema.Resource{
56+
Schema: map[string]*schema.Schema{
57+
"plan_type": {
58+
Type: schema.TypeString,
59+
Computed: true,
60+
Description: "Plan type. Possible values are: <li>plan-trial: Trial plan; </li><li>plan-personal: Personal plan; </li><li>plan-basic: Basic plan; </li><li>plan-standard: Standard plan; </li><li>plan-enterprise-v2: Enterprise plan; </li><li>plan-enterprise-model-a: Enterprise Model A plan. </li><li>plan-enterprise: Old Enterprise plan. </li>.",
61+
},
62+
"plan_id": {
63+
Type: schema.TypeString,
64+
Computed: true,
65+
Description: "Plan ID.",
66+
},
67+
"area": {
68+
Type: schema.TypeString,
69+
Computed: true,
70+
Description: "Service area, the values are: <li>mainland: Mainland China; </li><li>overseas: Worldwide (excluding Mainland China); </li><li>global: Worldwide (including Mainland China).</li>.",
71+
},
72+
"status": {
73+
Type: schema.TypeString,
74+
Computed: true,
75+
Description: "Package status, the values are: <li>normal: normal status; </li><li>expiring-soon: about to expire; </li><li>expired: expired; </li><li>isolated: isolated; </li><li>overdue-isolated: overdue isolated.</li>.",
76+
},
77+
"pay_mode": {
78+
Type: schema.TypeInt,
79+
Computed: true,
80+
Description: "Payment type, possible values: <li>0: post-payment; </li><li>1: pre-payment.</li>.",
81+
},
82+
"zones_info": {
83+
Type: schema.TypeList,
84+
Computed: true,
85+
Description: "Site information bound to the package, including site ID, site name, and site status.",
86+
Elem: &schema.Resource{
87+
Schema: map[string]*schema.Schema{
88+
"zone_id": {
89+
Type: schema.TypeString,
90+
Computed: true,
91+
Description: "Zone ID.",
92+
},
93+
"zone_name": {
94+
Type: schema.TypeString,
95+
Computed: true,
96+
Description: "Zone name.",
97+
},
98+
"paused": {
99+
Type: schema.TypeBool,
100+
Computed: true,
101+
Description: "Whether the site is disabled. The possible values are: <li>false: not disabled; </li><li>true: disabled.</li>.",
102+
},
103+
},
104+
},
105+
},
106+
"smart_request_capacity": {
107+
Type: schema.TypeInt,
108+
Computed: true,
109+
Description: "The number of intelligent acceleration requests in the package, unit: times.",
110+
},
111+
"vau_capacity": {
112+
Type: schema.TypeInt,
113+
Computed: true,
114+
Description: "VAU specifications in the package, unit: piece.",
115+
},
116+
"acc_traffic_capacity": {
117+
Type: schema.TypeInt,
118+
Computed: true,
119+
Description: "The content acceleration traffic specifications in the package, unit: byte.",
120+
},
121+
"smart_traffic_capacity": {
122+
Type: schema.TypeInt,
123+
Computed: true,
124+
Description: "Smart acceleration traffic specifications within the package, unit: byte.",
125+
},
126+
"ddos_traffic_capacity": {
127+
Type: schema.TypeInt,
128+
Computed: true,
129+
Description: "DDoS protection traffic specifications within the package, unit: bytes.",
130+
},
131+
"sec_traffic_capacity": {
132+
Type: schema.TypeInt,
133+
Computed: true,
134+
Description: "The security flow specification within the package, unit: byte.",
135+
},
136+
"sec_request_capacity": {
137+
Type: schema.TypeInt,
138+
Computed: true,
139+
Description: "The number of secure requests in the package, unit: times.",
140+
},
141+
"l4_traffic_capacity": {
142+
Type: schema.TypeInt,
143+
Computed: true,
144+
Description: "Layer 4 acceleration traffic specifications within the package, unit: byte.",
145+
},
146+
"cross_mlc_traffic_capacity": {
147+
Type: schema.TypeInt,
148+
Computed: true,
149+
Description: "The optimized traffic specifications of the Chinese mainland network in the package, unit: bytes.",
150+
},
151+
"bindable": {
152+
Type: schema.TypeString,
153+
Computed: true,
154+
Description: "Whether the package allows binding of new sites, the values are: <li>true: allows binding of new sites; </li><li>false: does not allow binding of new sites.</li>.",
155+
},
156+
"enabled_time": {
157+
Type: schema.TypeString,
158+
Computed: true,
159+
Description: "The package effective time.",
160+
},
161+
"expired_time": {
162+
Type: schema.TypeString,
163+
Computed: true,
164+
Description: "The expiration date of the package.",
165+
},
166+
"features": {
167+
Type: schema.TypeSet,
168+
Elem: &schema.Schema{
169+
Type: schema.TypeString,
170+
},
171+
Computed: true,
172+
Description: "The functions supported by the package have the following values: <li>ContentAcceleration: content acceleration function; </li><li>SmartAcceleration: smart acceleration function; </li><li>L4: four-layer acceleration function; </li><li>Waf: advanced web protection; </li><li>QUIC: QUIC function; </li><li>CrossMLC: Chinese mainland network optimization function; </li><li>ProcessMedia: media processing function; </li><li>L4DDoS: four-layer DDoS protection function; </li>L7DDoS function will only have one of the following specifications <li>L7DDoS.CM30G; seven-layer DDoS protection function - Chinese mainland 30G minimum bandwidth specification; </li><li>L7DDoS.CM60G; seven-layer DDoS protection function - Chinese mainland 60G minimum bandwidth specification; </li> <li>L7DDoS.CM100G; Layer 7 DDoS protection function - 100G guaranteed bandwidth for mainland China;</li><li>L7DDoS.Anycast300G; Layer 7 DDoS protection function - 300G guaranteed bandwidth for Anycast outside mainland China;</li><li>L7DDoS.AnycastUnlimited; Layer 7 DDoS protection function - unlimited full protection for Anycast outside mainland China;</li><li>L7DDoS.CM30G_Anycast300G; Layer 7 DDoS protection function - 30G guaranteed bandwidth for mainland China </li><li>L7DDoS.CM60G_Anycast300G; Layer 7 DDoS protection function - 60G guaranteed bandwidth in mainland China, 300G guaranteed bandwidth in anycast outside mainland China; </li><li>L7DDoS.CM100G_Anycast300G; Layer 7 DDoS protection function - 100G guaranteed bandwidth in mainland China, 300G guaranteed bandwidth in anycast outside mainland China; </li><li>L7DDoS.CM30G_AnycastUnlimited d; Layer 7 DDoS protection function - 30G guaranteed bandwidth in mainland China, unlimited Anycast protection outside mainland China; </li><li>L7DDoS.CM60G_AnycastUnlimited; Layer 7 DDoS protection function - 60G guaranteed bandwidth in mainland China, unlimited Anycast protection outside mainland China; </li><li>L7DDoS.CM100G_AnycastUnlimited; Layer 7 DDoS protection function - 100G guaranteed bandwidth in mainland China, unlimited Anycast protection outside mainland China; </li>.",
173+
},
174+
},
175+
},
176+
},
177+
178+
"result_output_file": {
179+
Type: schema.TypeString,
180+
Optional: true,
181+
Description: "Used to save results.",
182+
},
183+
},
184+
}
185+
}
186+
187+
func DataSourceTencentCloudTeoPlansRead(d *schema.ResourceData, meta interface{}) error {
188+
defer tccommon.LogElapsed("data_source.tencentcloud_teo_plans.read")()
189+
defer tccommon.InconsistentCheck(d, meta)()
190+
191+
var (
192+
logId = tccommon.GetLogId(nil)
193+
ctx = tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta)
194+
service = TeoService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
195+
)
196+
197+
paramMap := make(map[string]interface{})
198+
if v, ok := d.GetOk("filters"); ok {
199+
filtersSet := v.([]interface{})
200+
tmpSet := make([]*teo.Filter, 0, len(filtersSet))
201+
for _, item := range filtersSet {
202+
filter := teo.Filter{}
203+
filterMap := item.(map[string]interface{})
204+
if v, ok := filterMap["name"].(string); ok && v != "" {
205+
filter.Name = helper.String(v)
206+
}
207+
208+
if v, ok := filterMap["values"]; ok {
209+
valuesSet := v.(*schema.Set).List()
210+
filter.Values = helper.InterfacesStringsPoint(valuesSet)
211+
}
212+
213+
tmpSet = append(tmpSet, &filter)
214+
}
215+
216+
paramMap["filters"] = tmpSet
217+
}
218+
219+
if v, ok := d.GetOk("order"); ok {
220+
paramMap["Order"] = helper.String(v.(string))
221+
}
222+
223+
if v, ok := d.GetOk("direction"); ok {
224+
paramMap["Direction"] = helper.String(v.(string))
225+
}
226+
227+
var plans []*teo.Plan
228+
err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError {
229+
result, e := service.DescribeTeoPlansByFilters(ctx, paramMap)
230+
if e != nil {
231+
return tccommon.RetryError(e)
232+
}
233+
234+
plans = result
235+
return nil
236+
})
237+
238+
if err != nil {
239+
return err
240+
}
241+
242+
ids := make([]string, 0, len(plans))
243+
tmpList := make([]map[string]interface{}, 0, len(plans))
244+
if plans != nil {
245+
for _, plan := range plans {
246+
planMap := map[string]interface{}{}
247+
if plan.PlanType != nil {
248+
planMap["plan_type"] = plan.PlanType
249+
}
250+
251+
if plan.PlanId != nil {
252+
planMap["plan_id"] = plan.PlanId
253+
ids = append(ids, *plan.PlanId)
254+
}
255+
256+
if plan.Area != nil {
257+
planMap["area"] = plan.Area
258+
}
259+
260+
if plan.Status != nil {
261+
planMap["status"] = plan.Status
262+
}
263+
264+
if plan.PayMode != nil {
265+
planMap["pay_mode"] = plan.PayMode
266+
}
267+
268+
if plan.ZonesInfo != nil {
269+
zonesInfoList := []interface{}{}
270+
for _, zonesInfo := range plan.ZonesInfo {
271+
zonesInfoMap := map[string]interface{}{}
272+
if zonesInfo.ZoneId != nil {
273+
zonesInfoMap["zone_id"] = zonesInfo.ZoneId
274+
}
275+
276+
if zonesInfo.ZoneName != nil {
277+
zonesInfoMap["zone_name"] = zonesInfo.ZoneName
278+
}
279+
280+
if zonesInfo.Paused != nil {
281+
zonesInfoMap["paused"] = zonesInfo.Paused
282+
}
283+
284+
zonesInfoList = append(zonesInfoList, zonesInfoMap)
285+
}
286+
287+
planMap["zones_info"] = zonesInfoList
288+
}
289+
290+
if plan.SmartRequestCapacity != nil {
291+
planMap["smart_request_capacity"] = plan.SmartRequestCapacity
292+
}
293+
294+
if plan.VAUCapacity != nil {
295+
planMap["vau_capacity"] = plan.VAUCapacity
296+
}
297+
298+
if plan.AccTrafficCapacity != nil {
299+
planMap["acc_traffic_capacity"] = plan.AccTrafficCapacity
300+
}
301+
302+
if plan.SmartTrafficCapacity != nil {
303+
planMap["smart_traffic_capacity"] = plan.SmartTrafficCapacity
304+
}
305+
306+
if plan.DDoSTrafficCapacity != nil {
307+
planMap["ddos_traffic_capacity"] = plan.DDoSTrafficCapacity
308+
}
309+
310+
if plan.SecTrafficCapacity != nil {
311+
planMap["sec_traffic_capacity"] = plan.SecTrafficCapacity
312+
}
313+
314+
if plan.SecRequestCapacity != nil {
315+
planMap["sec_request_capacity"] = plan.SecRequestCapacity
316+
}
317+
318+
if plan.L4TrafficCapacity != nil {
319+
planMap["l4_traffic_capacity"] = plan.L4TrafficCapacity
320+
}
321+
322+
if plan.CrossMLCTrafficCapacity != nil {
323+
planMap["cross_mlc_traffic_capacity"] = plan.CrossMLCTrafficCapacity
324+
}
325+
326+
if plan.Bindable != nil {
327+
planMap["bindable"] = plan.Bindable
328+
}
329+
330+
if plan.EnabledTime != nil {
331+
planMap["enabled_time"] = plan.EnabledTime
332+
}
333+
334+
if plan.ExpiredTime != nil {
335+
planMap["expired_time"] = plan.ExpiredTime
336+
}
337+
338+
if plan.Features != nil {
339+
planMap["features"] = plan.Features
340+
}
341+
342+
tmpList = append(tmpList, planMap)
343+
}
344+
345+
_ = d.Set("plans", tmpList)
346+
}
347+
348+
d.SetId(helper.DataResourceIdsHash(ids))
349+
output, ok := d.GetOk("result_output_file")
350+
if ok && output.(string) != "" {
351+
if e := tccommon.WriteToFile(output.(string), tmpList); e != nil {
352+
return e
353+
}
354+
}
355+
356+
return nil
357+
}

0 commit comments

Comments
 (0)