Skip to content

Commit f19bd99

Browse files
authored
Merge pull request #12 from crab21/api_limit_copy
fix: remove remain coding of throttling service/api
2 parents d504eb4 + e24fc85 commit f19bd99

15 files changed

+145
-343
lines changed

examples/tencentcloud-api-gateway/main.tf

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ resource "tencentcloud_api_gateway_api" "api" {
2525
request_config_method = "POST"
2626

2727
request_parameters {
28-
name = "email"
28+
name = "email"
2929
position = "QUERY"
3030
type = "string"
3131
desc = "your email please?"
@@ -41,10 +41,10 @@ resource "tencentcloud_api_gateway_api" "api" {
4141
response_success_example = "<note>success</note>"
4242
response_fail_example = "<note>fail</note>"
4343
response_error_codes {
44-
code = 10
44+
code = 10
4545
msg = "system error"
46-
desc = "system error code"
47-
converted_code = -10
46+
desc = "system error code"
47+
converted_code = -10
4848
need_convert = true
4949
}
5050

@@ -90,16 +90,16 @@ resource "tencentcloud_api_gateway_usage_plan_attachment" "attach_service" {
9090
}
9191

9292
resource "tencentcloud_api_gateway_service_release" "service" {
93-
service_id = tencentcloud_api_gateway_throttling_api.service.service_id
93+
service_id = tencentcloud_api_gateway_service.service.id
9494
environment_name = "release"
9595
release_desc = var.release_desc
9696
}
9797

9898
resource "tencentcloud_api_gateway_strategy_attachment" "test"{
99-
service_id = tencentcloud_api_gateway_service_release.service.service_id
100-
strategy_id = tencentcloud_api_gateway_ip_strategy.test.strategy_id
101-
environment_name = "release"
102-
bind_api_id = tencentcloud_api_gateway_api.api.id
99+
service_id = tencentcloud_api_gateway_service_release.service.service_id
100+
strategy_id = tencentcloud_api_gateway_ip_strategy.test.strategy_id
101+
environment_name = "release"
102+
bind_api_id = tencentcloud_api_gateway_api.api.id
103103
}
104104

105105
data "tencentcloud_api_gateway_api_keys" "name" {
@@ -142,11 +142,11 @@ data "tencentcloud_api_gateway_services" "id" {
142142
}
143143

144144
data "tencentcloud_api_gateway_throttling_apis" "id" {
145-
service_id = tencentcloud_api_gateway_throttling_api.service.service_id
145+
service_id = tencentcloud_api_gateway_service.service.id
146146
}
147147

148148
data "tencentcloud_api_gateway_throttling_apis" "foo" {
149-
service_id = tencentcloud_api_gateway_throttling_api.service.service_id
149+
service_id = tencentcloud_api_gateway_service.service.id
150150
environment_names = ["release", "test"]
151151
}
152152

tencentcloud/data_source_tc_api_gateway_throttling_apis.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,19 @@ resource "tencentcloud_api_gateway_api" "api" {
4343
desc = "system error code"
4444
converted_code = -10
4545
need_convert = true
46-
}
47-
}
46+
}
4847
49-
resource "tencentcloud_api_gateway_throttling_api" "service" {
50-
service_id = tencentcloud_api_gateway_service.service.id
51-
strategy = "400"
52-
environment_name = "test"
53-
api_ids = [tencentcloud_api_gateway_api.api.id]
48+
release_limit = 100
49+
pre_limit = 100
50+
test_limit = 100
5451
}
5552
5653
data "tencentcloud_api_gateway_throttling_apis" "id" {
57-
service_id = tencentcloud_api_gateway_throttling_api.service.service_id
54+
service_id = tencentcloud_api_gateway_api.service_id
5855
}
5956
6057
data "tencentcloud_api_gateway_throttling_apis" "foo" {
61-
service_id = tencentcloud_api_gateway_throttling_api.service.service_id
58+
service_id = tencentcloud_api_gateway_api.service.service_id
6259
environment_names = ["release", "test"]
6360
}
6461
```

tencentcloud/data_source_tc_api_gateway_throttling_apis_test.go

Lines changed: 11 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
package tencentcloud
22

33
import (
4-
"context"
5-
"fmt"
6-
"strings"
74
"testing"
85

96
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
10-
"github.com/hashicorp/terraform-plugin-sdk/terraform"
117
)
128

139
var testAPIGatewaythrottlingApiDataSourceName = "data.tencentcloud_api_gateway_throttling_apis"
@@ -16,12 +12,12 @@ func TestAccTencentAPIGatewayThrottlingApisDataSource(t *testing.T) {
1612
resource.Test(t, resource.TestCase{
1713
PreCheck: func() { testAccPreCheck(t) },
1814
Providers: testAccProviders,
19-
CheckDestroy: testAccCheckThrottlingAPIDestroy,
15+
CheckDestroy: testAccCheckAPIGatewayAPIDestroy,
2016
Steps: []resource.TestStep{
2117
{
2218
Config: testAccTestAccTencentAPIGatewayThrottlingApis(),
2319
Check: resource.ComposeAggregateTestCheckFunc(
24-
testAccCheckThrottlingAPIExists("tencentcloud_api_gateway_throttling_api.service"),
20+
testAccCheckAPIGatewayAPIExists("tencentcloud_api_gateway_api.api"),
2521
resource.TestCheckResourceAttrSet(testAPIGatewaythrottlingApiDataSourceName+".id", "list.#"),
2622
resource.TestCheckResourceAttrSet(testAPIGatewaythrottlingApiDataSourceName+".id", "list.0.service_id"),
2723
resource.TestCheckResourceAttrSet(testAPIGatewaythrottlingApiDataSourceName+".id", "list.0.api_environment_strategies.#"),
@@ -49,87 +45,6 @@ func TestAccTencentAPIGatewayThrottlingApisDataSource(t *testing.T) {
4945
})
5046
}
5147

52-
func testAccCheckThrottlingAPIDestroy(s *terraform.State) error {
53-
var (
54-
logId = getLogId(contextNil)
55-
ctx = context.WithValue(context.TODO(), logIdKey, logId)
56-
throttlingService = APIGatewayService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn}
57-
)
58-
for _, rs := range s.RootModule().Resources {
59-
if rs.Type != "tencentcloud_api_gateway_throttling_api" {
60-
continue
61-
}
62-
63-
serviceId := rs.Primary.Attributes["service_id"]
64-
environmentName := rs.Primary.Attributes["environment_name"]
65-
apiIds := rs.Primary.Attributes["api_ids"]
66-
environmentList, err := throttlingService.DescribeApiEnvironmentStrategyList(ctx, serviceId, []string{environmentName}, "")
67-
if err != nil {
68-
return err
69-
}
70-
71-
for _, v := range environmentList {
72-
if v == nil || !strings.Contains(apiIds, *v.ApiId) {
73-
continue
74-
}
75-
environmentSet := v.EnvironmentStrategySet
76-
for _, env := range environmentSet {
77-
if env == nil || *env.EnvironmentName != environmentName {
78-
continue
79-
}
80-
81-
if *env.Quota == QUOTA || *env.Quota == QUOTA_MAX {
82-
continue
83-
}
84-
return fmt.Errorf("throttling API still not restore: %s", rs.Primary.ID)
85-
}
86-
}
87-
}
88-
return nil
89-
}
90-
91-
func testAccCheckThrottlingAPIExists(n string) resource.TestCheckFunc {
92-
return func(s *terraform.State) error {
93-
var (
94-
logId = getLogId(contextNil)
95-
ctx = context.WithValue(context.TODO(), logIdKey, logId)
96-
throttlingService = APIGatewayService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn}
97-
)
98-
99-
rs, ok := s.RootModule().Resources[n]
100-
if !ok {
101-
return fmt.Errorf("API Getway throttling API %s is not found", n)
102-
}
103-
if rs.Primary.ID == "" {
104-
return fmt.Errorf("API Getway throttling API id is not set")
105-
}
106-
serviceId := rs.Primary.Attributes["service_id"]
107-
environmentName := rs.Primary.Attributes["environment_name"]
108-
apiIds := rs.Primary.Attributes["api_ids"]
109-
environmentList, err := throttlingService.DescribeApiEnvironmentStrategyList(ctx, serviceId, []string{environmentName}, "")
110-
if err != nil {
111-
return err
112-
}
113-
114-
for _, v := range environmentList {
115-
if v == nil || !strings.Contains(apiIds, *v.ApiId) {
116-
continue
117-
}
118-
environmentSet := v.EnvironmentStrategySet
119-
for _, env := range environmentSet {
120-
if env == nil || *env.EnvironmentName != environmentName {
121-
continue
122-
}
123-
124-
if *env.Quota == QUOTA {
125-
return fmt.Errorf("throttling API still not set value: %s", rs.Primary.ID)
126-
}
127-
}
128-
}
129-
return nil
130-
}
131-
}
132-
13348
func testAccTestAccTencentAPIGatewayThrottlingApis() string {
13449
return `
13550
resource "tencentcloud_api_gateway_service" "service" {
@@ -164,29 +79,27 @@ resource "tencentcloud_api_gateway_api" "api" {
16479
service_config_method = "POST"
16580
response_type = "XML"
16681
response_success_example = "<note>success</note>"
167-
response_fail_example = "<note>fail</note>"
82+
response_fail_example = "<note>fail</note>"
83+
16884
response_error_codes {
16985
code = 10
17086
msg = "system error"
17187
desc = "system error code"
17288
converted_code = -10
17389
need_convert = true
174-
}
175-
}
176-
177-
resource "tencentcloud_api_gateway_throttling_api" "service" {
178-
service_id = tencentcloud_api_gateway_service.service.id
179-
strategy = "400"
180-
environment_name = "test"
181-
api_ids = [tencentcloud_api_gateway_api.api.id]
90+
}
91+
92+
release_limit = 100
93+
pre_limit = 100
94+
test_limit = 100
18295
}
18396
18497
data "tencentcloud_api_gateway_throttling_apis" "id" {
185-
service_id = tencentcloud_api_gateway_throttling_api.service.service_id
98+
service_id = tencentcloud_api_gateway_api.api.service_id
18699
}
187100
188101
data "tencentcloud_api_gateway_throttling_apis" "foo" {
189-
service_id = tencentcloud_api_gateway_throttling_api.service.service_id
102+
service_id = tencentcloud_api_gateway_api.api.service_id
190103
environment_names = ["release", "test"]
191104
}
192105
`

tencentcloud/data_source_tc_api_gateway_throttling_services.go

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +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-
}
14-
15-
resource "tencentcloud_api_gateway_throttling_service" "service" {
16-
service_id = tencentcloud_api_gateway_service.service.id
17-
strategy = "400"
18-
environment_names = ["release"]
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 = 100
14+
pre_limit = 100
15+
test_limit = 100
1916
}
2017
2118
data "tencentcloud_api_gateway_throttling_services" "id" {
22-
service_id = tencentcloud_api_gateway_throttling_service.service.service_id
19+
service_id = tencentcloud_api_gateway_service.service.id
2320
}
2421
```
2522
*/

0 commit comments

Comments
 (0)