Skip to content

Commit 07a65e4

Browse files
authored
Fix/apigw custom domain bug (#1738)
* feat/support-apigw-apidoc & apiapp * add changelog * add * fix/apigw-custom_domain-bug * fix/apigw-custom_domain-bug * fix/apigw-custom_domain-bug * fix/apigw-custom_domain-bug * fix/apigw-custom_domain-bug * fix/apigw-custom_domain-bug * add
1 parent 3514755 commit 07a65e4

22 files changed

+1713
-7
lines changed

.changelog/1726.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
```release-note:new-data-source
2+
tencentcloud_api_gateway_api_docs
3+
```
4+
5+
```release-note:new-resource
6+
tencentcloud_api_gateway_api_doc
7+
```
8+
9+
```release-note:new-data-source
10+
tencentcloud_api_gateway_api_apps
11+
```
12+
13+
```release-note:new-resource
14+
tencentcloud_api_gateway_api_app
15+
```
16+
17+
```release-note:enhancement
18+
resource/tencentcloud_api_gateway_custom_domain: support add `is_forced_https` params
19+
```

examples/tencentcloud-api-gateway/main.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,13 @@ resource "tencentcloud_api_gateway_strategy_attachment" "test"{
102102
bind_api_id = tencentcloud_api_gateway_api.api.id
103103
}
104104

105+
resource "tencentcloud_api_gateway_api_doc" "my_api_doc" {
106+
api_doc_name = "create_doc_test"
107+
service_id = tencentcloud_api_gateway_service_release.service.service_id
108+
environment = "release"
109+
api_ids = [tencentcloud_api_gateway_api.api.id]
110+
}
111+
105112
data "tencentcloud_api_gateway_api_keys" "name" {
106113
secret_name = tencentcloud_api_gateway_api_key.test.secret_name
107114
}
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
/*
2+
Use this data source to query list information of api_gateway api_app
3+
4+
Example Usage
5+
6+
```hcl
7+
data "tencentcloud_api_gateway_api_apps" "test" {
8+
api_app_id = ["app-rj8t6zx3"]
9+
api_app_name = ["app_test"]
10+
}
11+
```
12+
*/
13+
package tencentcloud
14+
15+
import (
16+
"context"
17+
"log"
18+
19+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
20+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
21+
apigateway "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/apigateway/v20180808"
22+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
23+
)
24+
25+
func dataSourceTencentCloudAPIGatewayAPIApps() *schema.Resource {
26+
return &schema.Resource{
27+
Read: dataSourceTencentCloudAPIGatewayAPIAppsRead,
28+
Schema: map[string]*schema.Schema{
29+
"result_output_file": {
30+
Type: schema.TypeString,
31+
Optional: true,
32+
Description: "Used to save results.",
33+
},
34+
35+
"api_app_id": {
36+
Type: schema.TypeString,
37+
Optional: true,
38+
Description: "Api app ID.",
39+
},
40+
41+
"api_app_name": {
42+
Type: schema.TypeString,
43+
Optional: true,
44+
Description: "Api app name.",
45+
},
46+
47+
"api_app_list": {
48+
Type: schema.TypeList,
49+
Computed: true,
50+
Description: "List of ApiApp.",
51+
Elem: &schema.Resource{
52+
Schema: map[string]*schema.Schema{
53+
"api_app_id": {
54+
Type: schema.TypeString,
55+
Computed: true,
56+
Description: "ApiApp ID.",
57+
},
58+
"api_app_name": {
59+
Type: schema.TypeString,
60+
Computed: true,
61+
Description: "ApiApp Name.",
62+
},
63+
"api_app_key": {
64+
Type: schema.TypeString,
65+
Computed: true,
66+
Description: "ApiApp key.",
67+
},
68+
"api_app_secret": {
69+
Type: schema.TypeString,
70+
Computed: true,
71+
Description: "ApiApp secret.",
72+
},
73+
"created_time": {
74+
Type: schema.TypeString,
75+
Computed: true,
76+
Description: "ApiApp create time.",
77+
},
78+
"modified_time": {
79+
Type: schema.TypeString,
80+
Computed: true,
81+
Description: "ApiApp modified time.",
82+
},
83+
"api_app_desc": {
84+
Type: schema.TypeString,
85+
Computed: true,
86+
Description: "ApiApp description.",
87+
},
88+
},
89+
},
90+
},
91+
},
92+
}
93+
}
94+
95+
func dataSourceTencentCloudAPIGatewayAPIAppsRead(d *schema.ResourceData, meta interface{}) error {
96+
defer logElapsed("data_source.tencentcloud_api_gateway_api_apps.read")()
97+
defer inconsistentCheck(d, meta)()
98+
99+
var (
100+
logId = getLogId(contextNil)
101+
ctx = context.WithValue(context.TODO(), logIdKey, logId)
102+
apiGatewayService = APIGatewayService{client: meta.(*TencentCloudClient).apiV3Conn}
103+
apiAppId, apiAppName string
104+
apiApps []*apigateway.ApiAppInfo
105+
)
106+
107+
if v, ok := d.GetOk("api_app_id"); ok {
108+
apiAppId = v.(string)
109+
}
110+
111+
if v, ok := d.GetOk("api_app_name"); ok {
112+
apiAppName = v.(string)
113+
}
114+
115+
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
116+
result, e := apiGatewayService.DescribeApiAppList(ctx, apiAppId, apiAppName)
117+
if e != nil {
118+
return retryError(e)
119+
}
120+
apiApps = result
121+
return nil
122+
})
123+
124+
if err != nil {
125+
log.Printf("[CRITAL]%s read api_gateway apiApps failed, reason:%+v", logId, err)
126+
return err
127+
}
128+
129+
apiAppList := []interface{}{}
130+
ids := make([]string, 0, len(apiApps))
131+
if apiApps != nil {
132+
for _, item := range apiApps {
133+
docMap := map[string]interface{}{}
134+
if item.ApiAppId != nil {
135+
docMap["api_app_id"] = item.ApiAppId
136+
}
137+
if item.ApiAppName != nil {
138+
docMap["api_app_name"] = item.ApiAppName
139+
}
140+
if item.ApiAppKey != nil {
141+
docMap["api_app_key"] = item.ApiAppKey
142+
}
143+
if item.ApiAppSecret != nil {
144+
docMap["api_app_secret"] = item.ApiAppSecret
145+
}
146+
if item.CreatedTime != nil {
147+
docMap["created_time"] = item.CreatedTime
148+
}
149+
if item.ModifiedTime != nil {
150+
docMap["modified_time"] = item.ModifiedTime
151+
}
152+
if item.ApiAppDesc != nil {
153+
docMap["api_app_desc"] = item.ApiAppDesc
154+
}
155+
apiAppList = append(apiAppList, docMap)
156+
ids = append(ids, *item.ApiAppId)
157+
}
158+
_ = d.Set("api_app_list", apiAppList)
159+
}
160+
161+
d.SetId(helper.DataResourceIdsHash(ids))
162+
output, ok := d.GetOk("result_output_file")
163+
if ok && output.(string) != "" {
164+
if e := writeToFile(output.(string), apiAppList); e != nil {
165+
return e
166+
}
167+
}
168+
169+
return nil
170+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
)
8+
9+
var testAPIGatewayAPIAppsResourceName = "data.tencentcloud_api_gateway_api_apps"
10+
11+
// go test -i; go test -test.run TestAccTencentAPIGatewayAPIAppsDataSource_basic -v
12+
func TestAccTencentAPIGatewayAPIAppsDataSource_basic(t *testing.T) {
13+
t.Parallel()
14+
resource.Test(t, resource.TestCase{
15+
PreCheck: func() { testAccPreCheck(t) },
16+
Providers: testAccProviders,
17+
CheckDestroy: testAccCheckAPIGatewayAPIAppDestroy,
18+
Steps: []resource.TestStep{
19+
{
20+
Config: testAccTestAccTencentAPIGatewayAPIApps(),
21+
Check: resource.ComposeAggregateTestCheckFunc(
22+
testAccCheckAPIGatewayAPIAppExists(testAPIGatewayAPIAppResourceName+".test"),
23+
resource.TestCheckResourceAttr(testAPIGatewayAPIAppsResourceName+".test", "api_app_list.#", "1"),
24+
resource.TestCheckResourceAttrSet(testAPIGatewayAPIAppsResourceName+".test", "api_app_list.0.api_app_id"),
25+
resource.TestCheckResourceAttrSet(testAPIGatewayAPIAppsResourceName+".test", "api_app_list.0.api_app_name"),
26+
resource.TestCheckResourceAttrSet(testAPIGatewayAPIAppsResourceName+".test", "api_app_list.0.api_app_key"),
27+
resource.TestCheckResourceAttrSet(testAPIGatewayAPIAppsResourceName+".test", "api_app_list.0.api_app_secret"),
28+
resource.TestCheckResourceAttrSet(testAPIGatewayAPIAppsResourceName+".test", "api_app_list.0.created_time"),
29+
resource.TestCheckResourceAttrSet(testAPIGatewayAPIAppsResourceName+".test", "api_app_list.0.modified_time"),
30+
resource.TestCheckResourceAttrSet(testAPIGatewayAPIAppsResourceName+".test", "api_app_list.0.api_app_desc"),
31+
),
32+
},
33+
},
34+
})
35+
}
36+
37+
func testAccTestAccTencentAPIGatewayAPIApps() string {
38+
return `
39+
resource "tencentcloud_api_gateway_api_app" "test" {
40+
api_app_name = "app_test1"
41+
api_app_desc = "create app desc"
42+
}
43+
44+
data "tencentcloud_api_gateway_api_apps" "test" {
45+
api_app_id = tencentcloud_api_gateway_api_app.test.id
46+
}
47+
`
48+
}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/*
2+
Use this data source to query list information of api_gateway api_doc
3+
Example Usage
4+
```hcl
5+
data "tencentcloud_api_gateway_api_docs" "my_api_doc" {
6+
}
7+
```
8+
*/
9+
package tencentcloud
10+
11+
import (
12+
"context"
13+
"log"
14+
15+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
16+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
17+
apigateway "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/apigateway/v20180808"
18+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
19+
)
20+
21+
func dataSourceTencentCloudAPIGatewayAPIDocs() *schema.Resource {
22+
return &schema.Resource{
23+
Read: dataSourceTencentCloudAPIGatewayAPIDocsRead,
24+
Schema: map[string]*schema.Schema{
25+
"result_output_file": {
26+
Type: schema.TypeString,
27+
Optional: true,
28+
Description: "Used to save results.",
29+
},
30+
31+
"api_doc_list": {
32+
Type: schema.TypeList,
33+
Computed: true,
34+
Description: "List of ApiDocs.",
35+
Elem: &schema.Resource{
36+
Schema: map[string]*schema.Schema{
37+
"api_doc_id": {
38+
Type: schema.TypeString,
39+
Computed: true,
40+
Description: "Api Doc ID.",
41+
},
42+
"api_doc_name": {
43+
Type: schema.TypeString,
44+
Computed: true,
45+
Description: "Api Doc Name.",
46+
},
47+
"api_doc_status": {
48+
Type: schema.TypeString,
49+
Computed: true,
50+
Description: "Api Doc Status.",
51+
},
52+
},
53+
},
54+
},
55+
},
56+
}
57+
}
58+
59+
func dataSourceTencentCloudAPIGatewayAPIDocsRead(d *schema.ResourceData, meta interface{}) error {
60+
defer logElapsed("data_source.tencentcloud_api_gateway_api_docs.read")()
61+
defer inconsistentCheck(d, meta)()
62+
63+
var (
64+
logId = getLogId(contextNil)
65+
ctx = context.WithValue(context.TODO(), logIdKey, logId)
66+
apiGatewayService = APIGatewayService{client: meta.(*TencentCloudClient).apiV3Conn}
67+
apiDoc []*apigateway.APIDoc
68+
)
69+
70+
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
71+
results, e := apiGatewayService.DescribeApiDocList(ctx)
72+
if e != nil {
73+
return retryError(e)
74+
}
75+
76+
apiDoc = results
77+
return nil
78+
})
79+
80+
if err != nil {
81+
log.Printf("[CRITAL]%s read api_gateway apiDocs failed, reason:%+v", logId, err)
82+
return err
83+
}
84+
85+
apiDocList := []interface{}{}
86+
ids := make([]string, 0, len(apiDoc))
87+
if apiDoc != nil {
88+
for _, item := range apiDoc {
89+
docMap := map[string]interface{}{}
90+
if item.ApiDocId != nil {
91+
docMap["api_doc_id"] = item.ApiDocId
92+
}
93+
if item.ApiDocName != nil {
94+
docMap["api_doc_name"] = item.ApiDocName
95+
}
96+
if item.ApiDocStatus != nil {
97+
docMap["api_doc_status"] = item.ApiDocStatus
98+
}
99+
apiDocList = append(apiDocList, docMap)
100+
ids = append(ids, *item.ApiDocId)
101+
}
102+
_ = d.Set("api_doc_list", apiDocList)
103+
}
104+
105+
d.SetId(helper.DataResourceIdsHash(ids))
106+
output, ok := d.GetOk("result_output_file")
107+
if ok && output.(string) != "" {
108+
if e := writeToFile(output.(string), apiDocList); e != nil {
109+
return e
110+
}
111+
}
112+
113+
return nil
114+
}

0 commit comments

Comments
 (0)