Skip to content

Commit 7ec3fd6

Browse files
gitmknanonymous
andauthored
feat: support tse datasource (#1964)
* feat: support tse datasource * feat: add changelog --------- Co-authored-by: anonymous <anonymous@mail.org>
1 parent dab2586 commit 7ec3fd6

File tree

16 files changed

+5983
-890
lines changed

16 files changed

+5983
-890
lines changed

.changelog/1964.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_tse_gateway_canary_rules
3+
```

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ require (
4242
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.693
4343
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.544
4444
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.663
45-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.699
45+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.701
4646
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.624
4747
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cwp v1.0.589
4848
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.692
@@ -86,7 +86,7 @@ require (
8686
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tem v1.0.578
8787
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo v1.0.529
8888
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tke v1.0.691
89-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tse v1.0.650
89+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tse v1.0.701
9090
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tsf v1.0.674
9191
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vod v1.0.199
9292
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc v1.0.669

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.696 h1:DcHz
861861
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.696/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
862862
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.699 h1:Unc4bMPZCAe964aOLHU05RAN59pMRNNy52E1fZ0My70=
863863
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.699/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
864+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.701 h1:ZOizvTamLWCqxIQKu8SkOJJRzrHyvqXa3E0quzJSBE0=
865+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.701/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
864866
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.624 h1:nEZqsoqt1pEoaP9JjkHQy3/H00suCfzlHW1qOm2nYD8=
865867
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.624/go.mod h1:+TXSVyeKwt1IhZRqKPbTREteBcP+K07Q846/ilNzLWA=
866868
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cwp v1.0.589 h1:LZihgirMH0vsaGScYexxwY0fTss9vHaSZs/YOQUVESg=
@@ -951,6 +953,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tke v1.0.691 h1:D+a7bZn
951953
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tke v1.0.691/go.mod h1:hsc/CPzbCRXqblCYuE1HuvP3G06OWA9zhAGI6AtEe5U=
952954
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tse v1.0.650 h1:gQFdOULR78GKaUwPkHnupLTZO5Z3STZ1xSp/83xZMnA=
953955
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tse v1.0.650/go.mod h1:cNgQjHihEHq9Z2n6sSe/l7gG6pf7nhWue7e+Iu+wQCc=
956+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tse v1.0.701 h1:k048M8hxerqIt9am5Hw9xJBmbJdPDxJd3Fzp2O1jlf0=
957+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tse v1.0.701/go.mod h1:t8LNOPsOOP1JtkDcZLtDu7dyAp4mwffBKu4Q+5Oyl/o=
954958
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tsf v1.0.674 h1:VsMV1/vsgVzespG7jUzraZS/AbAUllVQjmtVAlA9W/M=
955959
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tsf v1.0.674/go.mod h1:6+MWxaNR4y+spZHYNntulOyj628owTLuWmEFebJOWdA=
956960
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vod v1.0.199 h1:6Yt74l4pA5QtzhwMNIEUt0spXdSBKH744DDqTHJOCP0=
Lines changed: 310 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,310 @@
1+
/*
2+
Use this data source to query detailed information of tse gateway_canary_rules
3+
4+
Example Usage
5+
6+
```hcl
7+
data "tencentcloud_tse_gateway_canary_rules" "gateway_canary_rules" {
8+
gateway_id = "gateway-xxxxxx"
9+
service_id = "451a9920-e67a-4519-af41-fccac0e72005"
10+
}
11+
```
12+
*/
13+
package tencentcloud
14+
15+
import (
16+
"context"
17+
18+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
19+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
20+
tse "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tse/v20201207"
21+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
22+
)
23+
24+
func dataSourceTencentCloudTseGatewayCanaryRules() *schema.Resource {
25+
return &schema.Resource{
26+
Read: dataSourceTencentCloudTseGatewayCanaryRulesRead,
27+
Schema: map[string]*schema.Schema{
28+
"gateway_id": {
29+
Required: true,
30+
Type: schema.TypeString,
31+
Description: "gateway ID.",
32+
},
33+
34+
"service_id": {
35+
Required: true,
36+
Type: schema.TypeString,
37+
Description: "service ID.",
38+
},
39+
40+
"result": {
41+
Computed: true,
42+
Type: schema.TypeList,
43+
Description: "canary rule configuration.",
44+
Elem: &schema.Resource{
45+
Schema: map[string]*schema.Schema{
46+
"canary_rule_list": {
47+
Type: schema.TypeList,
48+
Computed: true,
49+
Description: "canary rule list.",
50+
Elem: &schema.Resource{
51+
Schema: map[string]*schema.Schema{
52+
"priority": {
53+
Type: schema.TypeInt,
54+
Computed: true,
55+
Description: "priority. The value ranges from 0 to 100; the larger the value, the higher the priority; the priority cannot be repeated between different rules.",
56+
},
57+
"enabled": {
58+
Type: schema.TypeBool,
59+
Computed: true,
60+
Description: "the status of canary rule.",
61+
},
62+
"condition_list": {
63+
Type: schema.TypeList,
64+
Computed: true,
65+
Description: "parameter matching condition list.",
66+
Elem: &schema.Resource{
67+
Schema: map[string]*schema.Schema{
68+
"type": {
69+
Type: schema.TypeString,
70+
Computed: true,
71+
Description: "type.Reference value:- path- method- query- header- cookie- body- system.",
72+
},
73+
"key": {
74+
Type: schema.TypeString,
75+
Computed: true,
76+
Description: "parameter name.",
77+
},
78+
"operator": {
79+
Type: schema.TypeString,
80+
Computed: true,
81+
Description: "operator.Reference value:`le`, `eq`, `lt`, `ne`, `ge`, `gt`, `regex`, `exists`, `in`, `not in`, `prefix`, `exact`, `regex`.",
82+
},
83+
"value": {
84+
Type: schema.TypeString,
85+
Computed: true,
86+
Description: "parameter value.",
87+
},
88+
"delimiter": {
89+
Type: schema.TypeString,
90+
Computed: true,
91+
Description: "delimiter. valid when operator is in or not in, reference value:`,`, `;`,`\\n`.",
92+
},
93+
"global_config_id": {
94+
Type: schema.TypeString,
95+
Computed: true,
96+
Description: "global configuration ID.",
97+
},
98+
"global_config_name": {
99+
Type: schema.TypeString,
100+
Computed: true,
101+
Description: "global configuration name.",
102+
},
103+
},
104+
},
105+
},
106+
"balanced_service_list": {
107+
Type: schema.TypeList,
108+
Computed: true,
109+
Description: "service weight configuration.",
110+
Elem: &schema.Resource{
111+
Schema: map[string]*schema.Schema{
112+
"service_id": {
113+
Type: schema.TypeString,
114+
Computed: true,
115+
Description: "service ID.",
116+
},
117+
"service_name": {
118+
Type: schema.TypeString,
119+
Computed: true,
120+
Description: "service name.",
121+
},
122+
"upstream_name": {
123+
Type: schema.TypeString,
124+
Computed: true,
125+
Description: "upstream name.",
126+
},
127+
"percent": {
128+
Type: schema.TypeFloat,
129+
Computed: true,
130+
Description: "percent, 10 is 10%, valid values: 0 to 100.",
131+
},
132+
},
133+
},
134+
},
135+
"service_id": {
136+
Type: schema.TypeString,
137+
Computed: true,
138+
Description: "service ID.",
139+
},
140+
"service_name": {
141+
Type: schema.TypeString,
142+
Computed: true,
143+
Description: "service name.",
144+
},
145+
},
146+
},
147+
},
148+
"total_count": {
149+
Type: schema.TypeInt,
150+
Computed: true,
151+
Description: "total count.",
152+
},
153+
},
154+
},
155+
},
156+
157+
"result_output_file": {
158+
Type: schema.TypeString,
159+
Optional: true,
160+
Description: "Used to save results.",
161+
},
162+
},
163+
}
164+
}
165+
166+
func dataSourceTencentCloudTseGatewayCanaryRulesRead(d *schema.ResourceData, meta interface{}) error {
167+
defer logElapsed("data_source.tencentcloud_tse_gateway_canary_rules.read")()
168+
defer inconsistentCheck(d, meta)()
169+
170+
logId := getLogId(contextNil)
171+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
172+
173+
var gatewayId string
174+
paramMap := make(map[string]interface{})
175+
if v, ok := d.GetOk("gateway_id"); ok {
176+
gatewayId = v.(string)
177+
paramMap["GatewayId"] = helper.String(v.(string))
178+
}
179+
180+
if v, ok := d.GetOk("service_id"); ok {
181+
paramMap["ServiceId"] = helper.String(v.(string))
182+
}
183+
184+
service := TseService{client: meta.(*TencentCloudClient).apiV3Conn}
185+
186+
var result *tse.CloudAPIGatewayCanaryRuleList
187+
188+
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
189+
response, e := service.DescribeTseGatewayCanaryRulesByFilter(ctx, paramMap)
190+
if e != nil {
191+
return retryError(e)
192+
}
193+
result = response
194+
return nil
195+
})
196+
if err != nil {
197+
return err
198+
}
199+
200+
cloudAPIGatewayCanaryRuleListMap := map[string]interface{}{}
201+
if result != nil {
202+
if result.CanaryRuleList != nil {
203+
canaryRuleListList := []interface{}{}
204+
for _, canaryRuleList := range result.CanaryRuleList {
205+
canaryRuleListMap := map[string]interface{}{}
206+
207+
if canaryRuleList.Priority != nil {
208+
canaryRuleListMap["priority"] = canaryRuleList.Priority
209+
}
210+
211+
if canaryRuleList.Enabled != nil {
212+
canaryRuleListMap["enabled"] = canaryRuleList.Enabled
213+
}
214+
215+
if canaryRuleList.ConditionList != nil {
216+
conditionListList := []interface{}{}
217+
for _, conditionList := range canaryRuleList.ConditionList {
218+
conditionListMap := map[string]interface{}{}
219+
220+
if conditionList.Type != nil {
221+
conditionListMap["type"] = conditionList.Type
222+
}
223+
224+
if conditionList.Key != nil {
225+
conditionListMap["key"] = conditionList.Key
226+
}
227+
228+
if conditionList.Operator != nil {
229+
conditionListMap["operator"] = conditionList.Operator
230+
}
231+
232+
if conditionList.Value != nil {
233+
conditionListMap["value"] = conditionList.Value
234+
}
235+
236+
if conditionList.Delimiter != nil {
237+
conditionListMap["delimiter"] = conditionList.Delimiter
238+
}
239+
240+
if conditionList.GlobalConfigId != nil {
241+
conditionListMap["global_config_id"] = conditionList.GlobalConfigId
242+
}
243+
244+
if conditionList.GlobalConfigName != nil {
245+
conditionListMap["global_config_name"] = conditionList.GlobalConfigName
246+
}
247+
248+
conditionListList = append(conditionListList, conditionListMap)
249+
}
250+
251+
canaryRuleListMap["condition_list"] = conditionListList
252+
}
253+
254+
if canaryRuleList.BalancedServiceList != nil {
255+
balancedServiceListList := []interface{}{}
256+
for _, balancedServiceList := range canaryRuleList.BalancedServiceList {
257+
balancedServiceListMap := map[string]interface{}{}
258+
259+
if balancedServiceList.ServiceID != nil {
260+
balancedServiceListMap["service_id"] = balancedServiceList.ServiceID
261+
}
262+
263+
if balancedServiceList.ServiceName != nil {
264+
balancedServiceListMap["service_name"] = balancedServiceList.ServiceName
265+
}
266+
267+
if balancedServiceList.UpstreamName != nil {
268+
balancedServiceListMap["upstream_name"] = balancedServiceList.UpstreamName
269+
}
270+
271+
if balancedServiceList.Percent != nil {
272+
balancedServiceListMap["percent"] = balancedServiceList.Percent
273+
}
274+
275+
balancedServiceListList = append(balancedServiceListList, balancedServiceListMap)
276+
}
277+
278+
canaryRuleListMap["balanced_service_list"] = balancedServiceListList
279+
}
280+
281+
if canaryRuleList.ServiceId != nil {
282+
canaryRuleListMap["service_id"] = canaryRuleList.ServiceId
283+
}
284+
285+
if canaryRuleList.ServiceName != nil {
286+
canaryRuleListMap["service_name"] = canaryRuleList.ServiceName
287+
}
288+
289+
canaryRuleListList = append(canaryRuleListList, canaryRuleListMap)
290+
}
291+
292+
cloudAPIGatewayCanaryRuleListMap["canary_rule_list"] = canaryRuleListList
293+
}
294+
295+
if result.TotalCount != nil {
296+
cloudAPIGatewayCanaryRuleListMap["total_count"] = result.TotalCount
297+
}
298+
299+
_ = d.Set("result", []interface{}{cloudAPIGatewayCanaryRuleListMap})
300+
}
301+
302+
d.SetId(gatewayId)
303+
output, ok := d.GetOk("result_output_file")
304+
if ok && output.(string) != "" {
305+
if e := writeToFile(output.(string), cloudAPIGatewayCanaryRuleListMap); e != nil {
306+
return e
307+
}
308+
}
309+
return nil
310+
}

0 commit comments

Comments
 (0)