Skip to content

Commit a257b57

Browse files
gitmknanonymous
andauthored
feat: support tsf group (#1855)
* feat: support tsf group * feat: add changelog --------- Co-authored-by: anonymous <anonymous@mail.org>
1 parent 4c49f40 commit a257b57

22 files changed

+3148
-0
lines changed

.changelog/1855.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
```release-note:new-data-source
2+
tencentcloud_tsf_pod_instances
3+
```
4+
5+
```release-note:new-data-source
6+
tencentcloud_tsf_gateway_all_group_apis
7+
```
8+
9+
```release-note:new-data-source
10+
tencentcloud_tsf_group_gateways
11+
```
12+
13+
```release-note:new-data-source
14+
tencentcloud_tsf_usable_unit_namespaces
15+
```
16+
17+
```release-note:new-data-source
18+
tencentcloud_tsf_group_instances
19+
```
20+
21+
```release-note:new-data-source
22+
tencentcloud_tsf_group_config_release
23+
```
Lines changed: 263 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,263 @@
1+
/*
2+
Use this data source to query detailed information of tsf gateway_all_group_apis
3+
4+
Example Usage
5+
6+
```hcl
7+
data "tencentcloud_tsf_gateway_all_group_apis" "gateway_all_group_apis" {
8+
gateway_deploy_group_id = "group-aeoej4qy"
9+
search_word = "user"
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+
tsf "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tsf/v20180326"
21+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
22+
)
23+
24+
func dataSourceTencentCloudTsfGatewayAllGroupApis() *schema.Resource {
25+
return &schema.Resource{
26+
Read: dataSourceTencentCloudTsfGatewayAllGroupApisRead,
27+
Schema: map[string]*schema.Schema{
28+
"gateway_deploy_group_id": {
29+
Required: true,
30+
Type: schema.TypeString,
31+
Description: "gateway group Id.",
32+
},
33+
34+
"search_word": {
35+
Optional: true,
36+
Type: schema.TypeString,
37+
Description: "Search keyword, supports api group name or API path.",
38+
},
39+
40+
"result": {
41+
Computed: true,
42+
Type: schema.TypeList,
43+
Description: "Gateway group and API list information.",
44+
Elem: &schema.Resource{
45+
Schema: map[string]*schema.Schema{
46+
"gateway_deploy_group_id": {
47+
Type: schema.TypeString,
48+
Computed: true,
49+
Description: "Gateway deployment group ID.Note: This field may return null, which means no valid value was found.",
50+
},
51+
"gateway_deploy_group_name": {
52+
Type: schema.TypeString,
53+
Computed: true,
54+
Description: "Gateway deployment group name.Note: This field may return null, which means no valid value was found.",
55+
},
56+
"group_num": {
57+
Type: schema.TypeInt,
58+
Computed: true,
59+
Description: "Gateway deployment api group number.Note: This field may return null, which means no valid value was found.",
60+
},
61+
"groups": {
62+
Type: schema.TypeList,
63+
Computed: true,
64+
Description: "Gateway deployment api group list.Note: This field may return null, which means no valid value was found.",
65+
Elem: &schema.Resource{
66+
Schema: map[string]*schema.Schema{
67+
"group_id": {
68+
Type: schema.TypeString,
69+
Computed: true,
70+
Description: "api group id.Note: This field may return null, which means no valid value was found.",
71+
},
72+
"group_name": {
73+
Type: schema.TypeString,
74+
Computed: true,
75+
Description: "api group name.Note: This field may return null, which means no valid value was found.",
76+
},
77+
"group_api_count": {
78+
Type: schema.TypeInt,
79+
Computed: true,
80+
Description: "Number of APIs under the group. Note: This field may return null, which means no valid value was found.",
81+
},
82+
"group_apis": {
83+
Type: schema.TypeList,
84+
Computed: true,
85+
Description: "List of APIs under the group.Note: This field may return null, which means no valid value was found.",
86+
Elem: &schema.Resource{
87+
Schema: map[string]*schema.Schema{
88+
"api_id": {
89+
Type: schema.TypeString,
90+
Computed: true,
91+
Description: "API ID.",
92+
},
93+
"path": {
94+
Type: schema.TypeString,
95+
Computed: true,
96+
Description: "API path.",
97+
},
98+
"microservice_name": {
99+
Type: schema.TypeString,
100+
Computed: true,
101+
Description: "API service name.",
102+
},
103+
"method": {
104+
Type: schema.TypeString,
105+
Computed: true,
106+
Description: "API method.",
107+
},
108+
"namespace_name": {
109+
Type: schema.TypeString,
110+
Computed: true,
111+
Description: "namespace name.",
112+
},
113+
},
114+
},
115+
},
116+
"gateway_instance_type": {
117+
Type: schema.TypeString,
118+
Computed: true,
119+
Description: "Type of the gateway instance.Note: This field may return null, which means no valid value was found.",
120+
},
121+
"gateway_instance_id": {
122+
Type: schema.TypeString,
123+
Computed: true,
124+
Description: "gateway instance id.Note: This field may return null, which means no valid value was found.",
125+
},
126+
},
127+
},
128+
},
129+
},
130+
},
131+
},
132+
133+
"result_output_file": {
134+
Type: schema.TypeString,
135+
Optional: true,
136+
Description: "Used to save results.",
137+
},
138+
},
139+
}
140+
}
141+
142+
func dataSourceTencentCloudTsfGatewayAllGroupApisRead(d *schema.ResourceData, meta interface{}) error {
143+
defer logElapsed("data_source.tencentcloud_tsf_gateway_all_group_apis.read")()
144+
defer inconsistentCheck(d, meta)()
145+
146+
logId := getLogId(contextNil)
147+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
148+
149+
var gatewayDeployGroupId string
150+
paramMap := make(map[string]interface{})
151+
if v, ok := d.GetOk("gateway_deploy_group_id"); ok {
152+
gatewayDeployGroupId = v.(string)
153+
paramMap["GatewayDeployGroupId"] = helper.String(v.(string))
154+
}
155+
156+
if v, ok := d.GetOk("search_word"); ok {
157+
paramMap["SearchWord"] = helper.String(v.(string))
158+
}
159+
160+
service := TsfService{client: meta.(*TencentCloudClient).apiV3Conn}
161+
162+
var result *tsf.GatewayVo
163+
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
164+
response, e := service.DescribeTsfGatewayAllGroupApisByFilter(ctx, paramMap)
165+
if e != nil {
166+
return retryError(e)
167+
}
168+
result = response
169+
return nil
170+
})
171+
if err != nil {
172+
return err
173+
}
174+
175+
gatewayVoMap := map[string]interface{}{}
176+
if result != nil {
177+
178+
if result.GatewayDeployGroupId != nil {
179+
gatewayVoMap["gateway_deploy_group_id"] = result.GatewayDeployGroupId
180+
}
181+
182+
if result.GatewayDeployGroupName != nil {
183+
gatewayVoMap["gateway_deploy_group_name"] = result.GatewayDeployGroupName
184+
}
185+
186+
if result.GroupNum != nil {
187+
gatewayVoMap["group_num"] = result.GroupNum
188+
}
189+
190+
if result.Groups != nil {
191+
groupsList := []interface{}{}
192+
for _, groups := range result.Groups {
193+
groupsMap := map[string]interface{}{}
194+
195+
if groups.GroupId != nil {
196+
groupsMap["group_id"] = groups.GroupId
197+
}
198+
199+
if groups.GroupName != nil {
200+
groupsMap["group_name"] = groups.GroupName
201+
}
202+
203+
if groups.GroupApiCount != nil {
204+
groupsMap["group_api_count"] = groups.GroupApiCount
205+
}
206+
207+
if groups.GroupApis != nil {
208+
groupApisList := []interface{}{}
209+
for _, groupApis := range groups.GroupApis {
210+
groupApisMap := map[string]interface{}{}
211+
212+
if groupApis.ApiId != nil {
213+
groupApisMap["api_id"] = groupApis.ApiId
214+
}
215+
216+
if groupApis.Path != nil {
217+
groupApisMap["path"] = groupApis.Path
218+
}
219+
220+
if groupApis.MicroserviceName != nil {
221+
groupApisMap["microservice_name"] = groupApis.MicroserviceName
222+
}
223+
224+
if groupApis.Method != nil {
225+
groupApisMap["method"] = groupApis.Method
226+
}
227+
228+
if groupApis.NamespaceName != nil {
229+
groupApisMap["namespace_name"] = groupApis.NamespaceName
230+
}
231+
232+
groupApisList = append(groupApisList, groupApisMap)
233+
}
234+
235+
groupsMap["group_apis"] = groupApisList
236+
}
237+
238+
if groups.GatewayInstanceType != nil {
239+
groupsMap["gateway_instance_type"] = groups.GatewayInstanceType
240+
}
241+
242+
if groups.GatewayInstanceId != nil {
243+
groupsMap["gateway_instance_id"] = groups.GatewayInstanceId
244+
}
245+
246+
groupsList = append(groupsList, groupsMap)
247+
}
248+
249+
gatewayVoMap["groups"] = groupsList
250+
}
251+
252+
_ = d.Set("result", []interface{}{gatewayVoMap})
253+
}
254+
255+
d.SetId(helper.DataResourceIdsHash([]string{gatewayDeployGroupId}))
256+
output, ok := d.GetOk("result_output_file")
257+
if ok && output.(string) != "" {
258+
if e := writeToFile(output.(string), gatewayVoMap); e != nil {
259+
return e
260+
}
261+
}
262+
return nil
263+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
)
8+
9+
// go test -i; go test -test.run TestAccTencentCloudTsfGatewayAllGroupApisDataSource_basic -v
10+
func TestAccTencentCloudTsfGatewayAllGroupApisDataSource_basic(t *testing.T) {
11+
t.Parallel()
12+
resource.Test(t, resource.TestCase{
13+
PreCheck: func() { testAccPreCheckCommon(t, ACCOUNT_TYPE_TSF) },
14+
Providers: testAccProviders,
15+
Steps: []resource.TestStep{
16+
{
17+
Config: testAccTsfGatewayAllGroupApisDataSource,
18+
Check: resource.ComposeTestCheckFunc(
19+
testAccCheckTencentCloudDataSourceID("data.tencentcloud_tsf_gateway_all_group_apis.gateway_all_group_apis"),
20+
resource.TestCheckResourceAttrSet("data.tencentcloud_tsf_gateway_all_group_apis.gateway_all_group_apis", "result.#"),
21+
resource.TestCheckResourceAttrSet("data.tencentcloud_tsf_gateway_all_group_apis.gateway_all_group_apis", "result.0.gateway_deploy_group_id"),
22+
resource.TestCheckResourceAttrSet("data.tencentcloud_tsf_gateway_all_group_apis.gateway_all_group_apis", "result.0.gateway_deploy_group_name"),
23+
resource.TestCheckResourceAttrSet("data.tencentcloud_tsf_gateway_all_group_apis.gateway_all_group_apis", "result.0.group_num"),
24+
resource.TestCheckResourceAttrSet("data.tencentcloud_tsf_gateway_all_group_apis.gateway_all_group_apis", "result.0.groups.#"),
25+
resource.TestCheckResourceAttrSet("data.tencentcloud_tsf_gateway_all_group_apis.gateway_all_group_apis", "result.0.groups.0.gateway_instance_id"),
26+
resource.TestCheckResourceAttrSet("data.tencentcloud_tsf_gateway_all_group_apis.gateway_all_group_apis", "result.0.groups.0.gateway_instance_type"),
27+
resource.TestCheckResourceAttrSet("data.tencentcloud_tsf_gateway_all_group_apis.gateway_all_group_apis", "result.0.groups.0.group_api_count"),
28+
resource.TestCheckResourceAttrSet("data.tencentcloud_tsf_gateway_all_group_apis.gateway_all_group_apis", "result.0.groups.0.group_apis.#"),
29+
resource.TestCheckResourceAttrSet("data.tencentcloud_tsf_gateway_all_group_apis.gateway_all_group_apis", "result.0.groups.0.group_apis.0.api_id"),
30+
resource.TestCheckResourceAttrSet("data.tencentcloud_tsf_gateway_all_group_apis.gateway_all_group_apis", "result.0.groups.0.group_apis.0.method"),
31+
resource.TestCheckResourceAttrSet("data.tencentcloud_tsf_gateway_all_group_apis.gateway_all_group_apis", "result.0.groups.0.group_apis.0.microservice_name"),
32+
resource.TestCheckResourceAttrSet("data.tencentcloud_tsf_gateway_all_group_apis.gateway_all_group_apis", "result.0.groups.0.group_apis.0.path"),
33+
),
34+
},
35+
},
36+
})
37+
}
38+
39+
const testAccTsfGatewayAllGroupApisDataSource = `
40+
41+
data "tencentcloud_tsf_gateway_all_group_apis" "gateway_all_group_apis" {
42+
gateway_deploy_group_id = "group-aeoej4qy"
43+
search_word = "user"
44+
}
45+
46+
`

0 commit comments

Comments
 (0)