Skip to content

Commit d504eb4

Browse files
authored
Merge pull request #11 from crab21/api_limit_copy
feat: remove throttling/service; combine api/service;
2 parents 0b82dc7 + 4786157 commit d504eb4

18 files changed

+511
-909
lines changed

CHANGELOG.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ FEATURES:
44

55
* **New Resource**: `tencentcloud_api_gateway_api`
66
* **New Resource**: `tencentcloud_api_gateway_service`
7-
* **New Resource**: `tencentcloud_api_gateway_throttling_api`
8-
* **New Resource**: `tencentcloud_api_gateway_throttling_service`
97
* **New Resource**: `tencentcloud_api_gateway_custom_domain`
108
* **New Resource**: `tencentcloud_api_gateway_usage_plan`
119
* **New Resource**: `tencentcloud_api_gateway_usage_plan_attachment`

examples/tencentcloud-api-gateway/main.tf

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ resource "tencentcloud_api_gateway_service" "service" {
99
service_desc = var.service_desc
1010
net_type = ["INNER", "OUTER"]
1111
ip_version = var.ip_version
12+
release_limit = 100
13+
pre_limit = 100
14+
test_limit = 100
1215
}
1316

1417
resource "tencentcloud_api_gateway_api" "api" {
@@ -44,6 +47,10 @@ resource "tencentcloud_api_gateway_api" "api" {
4447
converted_code = -10
4548
need_convert = true
4649
}
50+
51+
release_limit = 100
52+
pre_limit = 100
53+
test_limit = 100
4754
}
4855

4956
resource "tencentcloud_api_gateway_custom_domain" "foo" {
@@ -68,19 +75,6 @@ resource "tencentcloud_api_gateway_api_key_attachment" "attach" {
6875
usage_plan_id = tencentcloud_api_gateway_usage_plan.plan.id
6976
}
7077

71-
resource "tencentcloud_api_gateway_throttling_api" "service" {
72-
service_id = tencentcloud_api_gateway_service.service.id
73-
strategy = "400"
74-
environment_name = "test"
75-
api_ids = [tencentcloud_api_gateway_api.api.id]
76-
}
77-
78-
resource "tencentcloud_api_gateway_throttling_service" "service" {
79-
service_id = tencentcloud_api_gateway_service.service.id
80-
strategy = "400"
81-
environment_names = ["release"]
82-
}
83-
8478
resource "tencentcloud_api_gateway_usage_plan" "plan" {
8579
usage_plan_name = var.usage_plan_name
8680
usage_plan_desc = var.usage_plan_desc

tencentcloud/data_source_tc_api_gateway_throttling_apis.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ func dataSourceTencentCloudAPIGatewayThrottlingApisRead(d *schema.ResourceData,
208208
}
209209

210210
for _, serviceIdTmp := range serviceIds {
211-
environmentList, err := apiGatewayService.DescribeApiEnvironmentStrategyList(ctx, serviceIdTmp, environmentNames)
211+
environmentList, err := apiGatewayService.DescribeApiEnvironmentStrategyList(ctx, serviceIdTmp, environmentNames, "")
212212
if err != nil {
213213
return err
214214
}

tencentcloud/data_source_tc_api_gateway_throttling_apis_test.go

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

33
import (
4+
"context"
5+
"fmt"
6+
"strings"
47
"testing"
58

69
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
10+
"github.com/hashicorp/terraform-plugin-sdk/terraform"
711
)
812

913
var testAPIGatewaythrottlingApiDataSourceName = "data.tencentcloud_api_gateway_throttling_apis"
@@ -45,6 +49,87 @@ func TestAccTencentAPIGatewayThrottlingApisDataSource(t *testing.T) {
4549
})
4650
}
4751

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+
48133
func testAccTestAccTencentAPIGatewayThrottlingApis() string {
49134
return `
50135
resource "tencentcloud_api_gateway_service" "service" {

tencentcloud/data_source_tc_api_gateway_throttling_services_test.go

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

33
import (
4+
"context"
5+
"fmt"
6+
"strings"
47
"testing"
58

69
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
10+
"github.com/hashicorp/terraform-plugin-sdk/terraform"
711
)
812

913
var testAPIGatewaythrottlingServiceDataSourceName = "data.tencentcloud_api_gateway_throttling_services"
@@ -31,6 +35,73 @@ func TestAccTencentAPIGatewayThrottlingServicesDataSource(t *testing.T) {
3135
})
3236
}
3337

38+
func testAccCheckThrottlingServiceDestroy(s *terraform.State) error {
39+
var (
40+
logId = getLogId(contextNil)
41+
ctx = context.WithValue(context.TODO(), logIdKey, logId)
42+
throttlingService = APIGatewayService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn}
43+
)
44+
for _, rs := range s.RootModule().Resources {
45+
if rs.Type != "tencentcloud_api_gateway_throttling_service" {
46+
continue
47+
}
48+
49+
serviceId := rs.Primary.Attributes["service_id"]
50+
environmentNames := rs.Primary.Attributes["environment_names"]
51+
environmentList, err := throttlingService.DescribeServiceEnvironmentStrategyList(ctx, serviceId)
52+
if err != nil {
53+
return err
54+
}
55+
56+
for _, v := range environmentList {
57+
if v == nil || !strings.Contains(environmentNames, *v.EnvironmentName) {
58+
continue
59+
}
60+
if *v.Strategy == STRATEGY || *v.Strategy == STRATEGY_MAX {
61+
continue
62+
}
63+
64+
return fmt.Errorf("throttling service still not restore: %s", rs.Primary.ID)
65+
}
66+
}
67+
return nil
68+
}
69+
70+
func testAccCheckThrottlingServiceExists(n string) resource.TestCheckFunc {
71+
return func(s *terraform.State) error {
72+
var (
73+
logId = getLogId(contextNil)
74+
ctx = context.WithValue(context.TODO(), logIdKey, logId)
75+
throttlingService = APIGatewayService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn}
76+
)
77+
78+
rs, ok := s.RootModule().Resources[n]
79+
if !ok {
80+
return fmt.Errorf("API gateway throttling service %s is not found", n)
81+
}
82+
if rs.Primary.ID == "" {
83+
return fmt.Errorf("API gateway throttling service id is not set")
84+
}
85+
86+
serviceId := rs.Primary.Attributes["service_id"]
87+
environmentNames := rs.Primary.Attributes["environment_names"]
88+
environmentList, err := throttlingService.DescribeServiceEnvironmentStrategyList(ctx, serviceId)
89+
if err != nil {
90+
return err
91+
}
92+
93+
for _, v := range environmentList {
94+
if v == nil || !strings.Contains(environmentNames, *v.EnvironmentName) {
95+
continue
96+
}
97+
if *v.Strategy == STRATEGY {
98+
return fmt.Errorf("throttling service still not set value: %s", rs.Primary.ID)
99+
}
100+
}
101+
return nil
102+
}
103+
}
104+
34105
func testAccTestAccTencentAPIGatewayThrottlingServices() string {
35106
return `
36107
resource "tencentcloud_api_gateway_service" "service" {

tencentcloud/provider.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ API GateWay
7070
Resource
7171
tencentcloud_api_gateway_api
7272
tencentcloud_api_gateway_service
73-
tencentcloud_api_gateway_throttling_api
74-
tencentcloud_api_gateway_throttling_service
7573
tencentcloud_api_gateway_custom_domain
7674
tencentcloud_api_gateway_usage_plan
7775
tencentcloud_api_gateway_usage_plan_attachment
@@ -861,8 +859,6 @@ func Provider() terraform.ResourceProvider {
861859
"tencentcloud_api_gateway_usage_plan_attachment": resourceTencentCloudAPIGatewayUsagePlanAttachment(),
862860
"tencentcloud_api_gateway_api": resourceTencentCloudAPIGatewayAPI(),
863861
"tencentcloud_api_gateway_service": resourceTencentCloudAPIGatewayService(),
864-
"tencentcloud_api_gateway_throttling_api": resourceTencentCloudAPIGatewayThrottlingAPI(),
865-
"tencentcloud_api_gateway_throttling_service": resourceTencentCloudAPIGatewayThrottlingService(),
866862
"tencentcloud_api_gateway_custom_domain": resourceTencentCloudAPIGatewayCustomDomain(),
867863
"tencentcloud_api_gateway_ip_strategy": resourceTencentCloudAPIGatewayIPStrategy(),
868864
"tencentcloud_api_gateway_strategy_attachment": resourceTencentCloudAPIGatewayStrategyAttachment(),

0 commit comments

Comments
 (0)