Skip to content

Commit 86d8546

Browse files
fix/api-gateway-service (#1898)
* fix/api-gateway-service * fix/api-gateway-service * fix/api-gateway-service * fix/api-gateway-service * fix/api-gateway-service * fix/api-gateway-service * fix/api-gateway-service * fix/api-gateway-service * fix/api-gateway-service * add changelog * fix testcases --------- Co-authored-by: hellertang <hellertang@tencent.com>
1 parent a3c456d commit 86d8546

File tree

5 files changed

+75
-17
lines changed

5 files changed

+75
-17
lines changed

.changelog/1898.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource/tencentcloud_api_gateway_service: support param `tags`.
3+
```

tencentcloud/common.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ var retryableErrorCode = []string{
8484
"InvalidParameter.ActionInProgress",
8585
// posgresql
8686
"OperationDenied.InstanceStatusLimitError",
87+
// apigw
88+
"UnsupportedOperation.UnsupportedDeleteService",
8789
}
8890

8991
// retryableCosErrorCode is retryable error code for COS/CI SDK

tencentcloud/resource_tc_api_gateway_service.go

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@ Example Usage
55
66
```hcl
77
resource "tencentcloud_api_gateway_service" "service" {
8-
service_name = "niceservice"
9-
protocol = "http&https"
10-
service_desc = "your nice service"
11-
net_type = ["INNER", "OUTER"]
12-
ip_version = "IPv4"
13-
release_limit = 500
14-
pre_limit = 500
15-
test_limit = 500
8+
service_name = "niceservice"
9+
protocol = "http&https"
10+
service_desc = "your nice service"
11+
net_type = ["INNER", "OUTER"]
12+
ip_version = "IPv4"
13+
tags = {
14+
test-key1 = "test-value1"
15+
test-key2 = "test-value2"
16+
}
17+
release_limit = 500
18+
pre_limit = 500
19+
test_limit = 500
1620
}
1721
```
1822
@@ -89,6 +93,11 @@ func resourceTencentCloudAPIGatewayService() *schema.Resource {
8993
ValidateFunc: validateAllowedStringValue(API_GATEWAY_NET_IP_VERSIONS),
9094
Description: "IP version number. Valid values: `IPv4`, `IPv6`. Default value: `IPv4`.",
9195
},
96+
"tags": {
97+
Type: schema.TypeMap,
98+
Optional: true,
99+
Description: "Tag description list.",
100+
},
92101
"release_limit": {
93102
Type: schema.TypeInt,
94103
Optional: true,
@@ -299,6 +308,15 @@ func resourceTencentCloudAPIGatewayServiceCreate(d *schema.ResourceData, meta in
299308
}
300309
}
301310

311+
if tags := helper.GetTags(d, "tags"); len(tags) > 0 {
312+
tagService := TagService{client: meta.(*TencentCloudClient).apiV3Conn}
313+
region := meta.(*TencentCloudClient).apiV3Conn.Region
314+
resourceName := fmt.Sprintf("qcs::apigw:%s:uin/:service/%s", region, serviceId)
315+
if err := tagService.ModifyTags(ctx, resourceName, tags, nil); err != nil {
316+
return err
317+
}
318+
}
319+
302320
d.SetId(serviceId)
303321

304322
return resourceTencentCloudAPIGatewayServiceRead(d, meta)
@@ -451,6 +469,15 @@ func resourceTencentCloudAPIGatewayServiceRead(d *schema.ResourceData, meta inte
451469
_ = d.Set("test_limit", testLimit)
452470
_ = d.Set("release_limit", releaseLimit)
453471

472+
tcClient := meta.(*TencentCloudClient).apiV3Conn
473+
tagService := &TagService{client: tcClient}
474+
tags, err := tagService.DescribeResourceTags(ctx, "apigw", "service", tcClient.Region, serviceId)
475+
if err != nil {
476+
return err
477+
}
478+
479+
_ = d.Set("tags", tags)
480+
454481
return nil
455482
}
456483

@@ -527,6 +554,17 @@ func resourceTencentCloudAPIGatewayServiceUpdate(d *schema.ResourceData, meta in
527554

528555
}
529556

557+
if d.HasChange("tags") {
558+
tcClient := meta.(*TencentCloudClient).apiV3Conn
559+
tagService := &TagService{client: tcClient}
560+
oldTags, newTags := d.GetChange("tags")
561+
replaceTags, deleteTags := diffTags(oldTags.(map[string]interface{}), newTags.(map[string]interface{}))
562+
resourceName := BuildTagResourceName("apigw", "service", tcClient.Region, serviceId)
563+
if err := tagService.ModifyTags(ctx, resourceName, replaceTags, deleteTags); err != nil {
564+
return err
565+
}
566+
}
567+
530568
d.Partial(false)
531569
return resourceTencentCloudAPIGatewayServiceRead(d, meta)
532570
}

tencentcloud/resource_tc_api_gateway_service_test.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import (
1212
var testAPIGatewayServiceResourceName = "tencentcloud_api_gateway_service"
1313
var testAPIGatewayServiceResourceKey = testAPIGatewayServiceResourceName + ".service"
1414

15-
func TestAccTencentCloudNeedFixAPIGateWayServiceResource(t *testing.T) {
15+
// go test -i; go test -test.run TestAccTencentCloudApiGateWayServiceResource_basic -v
16+
func TestAccTencentCloudApiGateWayServiceResource_basic(t *testing.T) {
1617
t.Parallel()
1718
resource.Test(t, resource.TestCase{
1819
PreCheck: func() { testAccPreCheck(t) },
@@ -30,15 +31,17 @@ func TestAccTencentCloudNeedFixAPIGateWayServiceResource(t *testing.T) {
3031
resource.TestCheckResourceAttrSet(testAPIGatewayServiceResourceKey, "create_time"),
3132
resource.TestCheckResourceAttrSet(testAPIGatewayServiceResourceKey, "internal_sub_domain"),
3233
resource.TestCheckResourceAttrSet(testAPIGatewayServiceResourceKey, "inner_http_port"),
34+
resource.TestCheckResourceAttr(testAPIGatewayServiceResourceKey, "tags.test-key", "test-value"),
3335
resource.TestCheckResourceAttr(testAPIGatewayServiceResourceKey, "release_limit", "500"),
3436
resource.TestCheckResourceAttr(testAPIGatewayServiceResourceKey, "pre_limit", "500"),
3537
resource.TestCheckResourceAttr(testAPIGatewayServiceResourceKey, "test_limit", "500"),
3638
),
3739
},
3840
{
39-
ResourceName: testAPIGatewayServiceResourceKey,
40-
ImportState: true,
41-
ImportStateVerify: true,
41+
ResourceName: testAPIGatewayServiceResourceKey,
42+
ImportState: true,
43+
ImportStateVerify: true,
44+
ImportStateVerifyIgnore: []string{"modify_time"},
4245
},
4346
{
4447
Config: testAccAPIGatewayServiceUpdate,
@@ -53,6 +56,7 @@ func TestAccTencentCloudNeedFixAPIGateWayServiceResource(t *testing.T) {
5356
resource.TestCheckResourceAttrSet(testAPIGatewayServiceResourceKey, "internal_sub_domain"),
5457
resource.TestCheckResourceAttrSet(testAPIGatewayServiceResourceKey, "outer_sub_domain"),
5558
resource.TestCheckResourceAttrSet(testAPIGatewayServiceResourceKey, "inner_http_port"),
59+
resource.TestCheckResourceAttr(testAPIGatewayServiceResourceKey, "tags.test-key1", "test-value1"),
5660
resource.TestCheckResourceAttr(testAPIGatewayServiceResourceKey, "release_limit", "100"),
5761
resource.TestCheckResourceAttr(testAPIGatewayServiceResourceKey, "pre_limit", "100"),
5862
resource.TestCheckResourceAttr(testAPIGatewayServiceResourceKey, "test_limit", "100"),
@@ -121,6 +125,9 @@ resource "tencentcloud_api_gateway_service" "service" {
121125
service_desc = "my nice service"
122126
net_type = ["INNER"]
123127
ip_version = "IPv4"
128+
tags = {
129+
test-key = "test-value"
130+
}
124131
release_limit = 500
125132
pre_limit = 500
126133
test_limit = 500
@@ -133,6 +140,9 @@ resource "tencentcloud_api_gateway_service" "service" {
133140
service_desc = "your nice service"
134141
net_type = ["INNER", "OUTER"]
135142
ip_version = "IPv4"
143+
tags = {
144+
test-key1 = "test-value1"
145+
}
136146
release_limit = 100
137147
pre_limit = 100
138148
test_limit = 100

website/docs/r/api_gateway_service.html.markdown

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,15 @@ Use this resource to create API gateway service.
1515

1616
```hcl
1717
resource "tencentcloud_api_gateway_service" "service" {
18-
service_name = "niceservice"
19-
protocol = "http&https"
20-
service_desc = "your nice service"
21-
net_type = ["INNER", "OUTER"]
22-
ip_version = "IPv4"
18+
service_name = "niceservice"
19+
protocol = "http&https"
20+
service_desc = "your nice service"
21+
net_type = ["INNER", "OUTER"]
22+
ip_version = "IPv4"
23+
tags = {
24+
test-key1 = "test-value1"
25+
test-key2 = "test-value2"
26+
}
2327
release_limit = 500
2428
pre_limit = 500
2529
test_limit = 500
@@ -38,6 +42,7 @@ The following arguments are supported:
3842
* `pre_limit` - (Optional, Int) API QPS value. Enter a positive number to limit the API query rate per second `QPS`.
3943
* `release_limit` - (Optional, Int) API QPS value. Enter a positive number to limit the API query rate per second `QPS`.
4044
* `service_desc` - (Optional, String) Custom service description.
45+
* `tags` - (Optional, Map) Tag description list.
4146
* `test_limit` - (Optional, Int) API QPS value. Enter a positive number to limit the API query rate per second `QPS`.
4247

4348
## Attributes Reference

0 commit comments

Comments
 (0)