Skip to content

Commit 9c2c255

Browse files
authored
Merge pull request #2126 from tencentcloudstack/fix/tse-optimization
fix: modify gateway
2 parents 20ed4e0 + 44d79b9 commit 9c2c255

11 files changed

+247
-34
lines changed

.changelog/2126.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
```release-note:enhancement
2+
resource/tencentcloud_tse_cngw_gateway: Support modifying `node_config`.
3+
```
4+
5+
```release-note:new-resource
6+
tencentcloud_tse_cngw_group
7+
```

tencentcloud/provider.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,6 +1605,7 @@ Tencent Cloud Service Engine(TSE)
16051605
tencentcloud_tse_cngw_service
16061606
tencentcloud_tse_cngw_canary_rule
16071607
tencentcloud_tse_cngw_gateway
1608+
tencentcloud_tse_cngw_group
16081609
tencentcloud_tse_cngw_service_rate_limit
16091610
tencentcloud_tse_cngw_route
16101611
tencentcloud_tse_cngw_route_rate_limit

tencentcloud/resource_tc_tse_cngw_gateway.go

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ func resourceTencentCloudTseCngwGateway() *schema.Resource {
145145

146146
"feature_version": {
147147
Optional: true,
148+
Computed: true,
148149
Type: schema.TypeString,
149150
Description: "product version. Reference value: `TRIAL`, `STANDARD`(default value), `PROFESSIONAL`.",
150151
},
@@ -157,12 +158,14 @@ func resourceTencentCloudTseCngwGateway() *schema.Resource {
157158

158159
"engine_region": {
159160
Optional: true,
161+
Computed: true,
160162
Type: schema.TypeString,
161163
Description: "engine region of gateway.",
162164
},
163165

164166
"ingress_class_name": {
165167
Optional: true,
168+
Computed: true,
166169
Type: schema.TypeString,
167170
Description: "ingress class name.",
168171
},
@@ -486,7 +489,7 @@ func resourceTencentCloudTseCngwGatewayUpdate(d *schema.ResourceData, meta inter
486489

487490
request.GatewayId = &gatewayId
488491

489-
immutableArgs := []string{"type", "gateway_version", "node_config", "vpc_config", "feature_version", "internet_max_bandwidth_out", "engine_region", "ingress_class_name", "trade_type", "internet_config"}
492+
immutableArgs := []string{"type", "gateway_version", "vpc_config", "feature_version", "internet_max_bandwidth_out", "engine_region", "ingress_class_name", "trade_type", "internet_config"}
490493
for _, v := range immutableArgs {
491494
if d.HasChange(v) {
492495
return fmt.Errorf("argument `%s` cannot be changed", v)
@@ -536,6 +539,60 @@ func resourceTencentCloudTseCngwGatewayUpdate(d *schema.ResourceData, meta inter
536539
}
537540
}
538541

542+
if d.HasChange("node_config") {
543+
// Get the default group id
544+
paramMap := make(map[string]interface{})
545+
paramMap["GatewayId"] = &gatewayId
546+
service := TseService{client: meta.(*TencentCloudClient).apiV3Conn}
547+
cngwGroup, err := service.DescribeTseGroupsByFilter(ctx, paramMap)
548+
if err != nil {
549+
return err
550+
}
551+
if len(cngwGroup.GatewayGroupList) < 1 {
552+
return fmt.Errorf("[WARN]%s resource `TseCngwGroup` [%s] not found, please check if it has been deleted.\n", logId, gatewayId)
553+
}
554+
groupId := ""
555+
for _, v := range cngwGroup.GatewayGroupList {
556+
if *v.IsFirstGroup == 1 {
557+
groupId = *v.GroupId
558+
break
559+
}
560+
}
561+
562+
nodeConfigRequest := tse.NewUpdateCloudNativeAPIGatewaySpecRequest()
563+
nodeConfigRequest.GatewayId = &gatewayId
564+
nodeConfigRequest.GroupId = &groupId
565+
566+
if dMap, ok := helper.InterfacesHeadMap(d, "node_config"); ok {
567+
cloudNativeAPIGatewayNodeConfig := tse.CloudNativeAPIGatewayNodeConfig{}
568+
if v, ok := dMap["specification"]; ok {
569+
cloudNativeAPIGatewayNodeConfig.Specification = helper.String(v.(string))
570+
}
571+
if v, ok := dMap["number"]; ok {
572+
cloudNativeAPIGatewayNodeConfig.Number = helper.IntInt64(v.(int))
573+
}
574+
nodeConfigRequest.NodeConfig = &cloudNativeAPIGatewayNodeConfig
575+
}
576+
577+
err = resource.Retry(writeRetryTimeout, func() *resource.RetryError {
578+
result, e := meta.(*TencentCloudClient).apiV3Conn.UseTseClient().UpdateCloudNativeAPIGatewaySpec(nodeConfigRequest)
579+
if e != nil {
580+
return retryError(e)
581+
} else {
582+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, nodeConfigRequest.GetAction(), nodeConfigRequest.ToJsonString(), result.ToJsonString())
583+
}
584+
return nil
585+
})
586+
if err != nil {
587+
log.Printf("[CRITAL]%s update tse cngwGateway failed, reason:%+v", logId, err)
588+
return err
589+
}
590+
591+
if err := service.CheckTseNativeAPIGatewayGroupStatusById(ctx, gatewayId, groupId, "update"); err != nil {
592+
return err
593+
}
594+
}
595+
539596
if d.HasChange("tags") {
540597
ctx := context.WithValue(context.TODO(), logIdKey, logId)
541598
tcClient := meta.(*TencentCloudClient).apiV3Conn

tencentcloud/resource_tc_tse_cngw_gateway_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ func TestAccTencentCloudTseCngwGatewayResource_basic(t *testing.T) {
4343
resource.TestCheckResourceAttr("tencentcloud_tse_cngw_gateway.cngw_gateway", "tags.createdBy", "terraform"),
4444
),
4545
},
46-
// {
47-
// ResourceName: "tencentcloud_tse_cngw_gateway.cngw_gateway",
48-
// ImportState: true,
49-
// ImportStateVerify: true,
50-
// },
46+
{
47+
ResourceName: "tencentcloud_tse_cngw_gateway.cngw_gateway",
48+
ImportState: true,
49+
ImportStateVerify: true,
50+
},
5151
{
5252
Config: testAccTseCngwGatewayUp,
5353
Check: resource.ComposeTestCheckFunc(

tencentcloud/resource_tc_tse_cngw_route.go

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ resource "tencentcloud_tse_cngw_service" "cngw_service" {
6767
6868
resource "tencentcloud_tse_cngw_route" "cngw_route" {
6969
destination_ports = []
70-
force_https = false
7170
gateway_id = tencentcloud_tse_cngw_gateway.cngw_gateway.id
7271
hosts = [
7372
"192.168.0.1:9090",
@@ -191,6 +190,7 @@ func resourceTencentCloudTseCngwRoute() *schema.Resource {
191190
"force_https": {
192191
Optional: true,
193192
Type: schema.TypeBool,
193+
Deprecated: "This field has been deprecated and will be deleted in subsequent versions.",
194194
Description: "whether to enable forced HTTPS, no longer use.",
195195
},
196196

@@ -476,7 +476,7 @@ func resourceTencentCloudTseCngwRouteUpdate(d *schema.ResourceData, meta interfa
476476
request.RouteName = &routeName
477477
request.RouteID = cngwRoute.ID
478478

479-
immutableArgs := []string{"gateway_id", "service_id", "route_name"}
479+
immutableArgs := []string{"gateway_id", "service_id", "route_name", "force_https"}
480480

481481
for _, v := range immutableArgs {
482482
if d.HasChange(v) {
@@ -494,33 +494,27 @@ func resourceTencentCloudTseCngwRouteUpdate(d *schema.ResourceData, meta interfa
494494
}
495495
}
496496

497-
if d.HasChange("hosts") {
498-
if v, ok := d.GetOk("hosts"); ok {
499-
hostsSet := v.(*schema.Set).List()
500-
for i := range hostsSet {
501-
hosts := hostsSet[i].(string)
502-
request.Hosts = append(request.Hosts, &hosts)
503-
}
497+
if v, ok := d.GetOk("hosts"); ok {
498+
hostsSet := v.(*schema.Set).List()
499+
for i := range hostsSet {
500+
hosts := hostsSet[i].(string)
501+
request.Hosts = append(request.Hosts, &hosts)
504502
}
505503
}
506504

507-
if d.HasChange("paths") {
508-
if v, ok := d.GetOk("paths"); ok {
509-
pathsSet := v.(*schema.Set).List()
510-
for i := range pathsSet {
511-
paths := pathsSet[i].(string)
512-
request.Paths = append(request.Paths, &paths)
513-
}
505+
if v, ok := d.GetOk("paths"); ok {
506+
pathsSet := v.(*schema.Set).List()
507+
for i := range pathsSet {
508+
paths := pathsSet[i].(string)
509+
request.Paths = append(request.Paths, &paths)
514510
}
515511
}
516512

517-
if d.HasChange("protocols") {
518-
if v, ok := d.GetOk("protocols"); ok {
519-
protocolsSet := v.(*schema.Set).List()
520-
for i := range protocolsSet {
521-
protocols := protocolsSet[i].(string)
522-
request.Protocols = append(request.Protocols, &protocols)
523-
}
513+
if v, ok := d.GetOk("protocols"); ok {
514+
protocolsSet := v.(*schema.Set).List()
515+
for i := range protocolsSet {
516+
protocols := protocolsSet[i].(string)
517+
request.Protocols = append(request.Protocols, &protocols)
524518
}
525519
}
526520

tencentcloud/resource_tc_tse_cngw_route_test.go

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ func TestAccTencentCloudTseCngwRouteResource_basic(t *testing.T) {
2626
testAccCheckTseCngwRouteExists("tencentcloud_tse_cngw_route.cngw_route"),
2727
resource.TestCheckResourceAttrSet("tencentcloud_tse_cngw_route.cngw_route", "id"),
2828
resource.TestCheckResourceAttr("tencentcloud_tse_cngw_route.cngw_route", "gateway_id", defaultTseGatewayId),
29-
resource.TestCheckResourceAttr("tencentcloud_tse_cngw_route.cngw_route", "force_https", "false"),
3029
resource.TestCheckResourceAttr("tencentcloud_tse_cngw_route.cngw_route", "hosts.#", "1"),
3130
resource.TestCheckResourceAttr("tencentcloud_tse_cngw_route.cngw_route", "https_redirect_status_code", "426"),
3231
resource.TestCheckResourceAttr("tencentcloud_tse_cngw_route.cngw_route", "paths.#", "1"),
@@ -45,6 +44,25 @@ func TestAccTencentCloudTseCngwRouteResource_basic(t *testing.T) {
4544
ImportState: true,
4645
ImportStateVerify: true,
4746
},
47+
{
48+
Config: testAccTseCngwRouteUp,
49+
Check: resource.ComposeTestCheckFunc(
50+
testAccCheckTseCngwRouteExists("tencentcloud_tse_cngw_route.cngw_route"),
51+
resource.TestCheckResourceAttrSet("tencentcloud_tse_cngw_route.cngw_route", "id"),
52+
resource.TestCheckResourceAttr("tencentcloud_tse_cngw_route.cngw_route", "gateway_id", defaultTseGatewayId),
53+
resource.TestCheckResourceAttr("tencentcloud_tse_cngw_route.cngw_route", "hosts.#", "1"),
54+
resource.TestCheckResourceAttr("tencentcloud_tse_cngw_route.cngw_route", "https_redirect_status_code", "301"),
55+
resource.TestCheckResourceAttr("tencentcloud_tse_cngw_route.cngw_route", "paths.#", "1"),
56+
resource.TestCheckResourceAttr("tencentcloud_tse_cngw_route.cngw_route", "headers.#", "1"),
57+
resource.TestCheckResourceAttr("tencentcloud_tse_cngw_route.cngw_route", "headers.0.key", "req"),
58+
resource.TestCheckResourceAttr("tencentcloud_tse_cngw_route.cngw_route", "headers.0.value", "terraform1"),
59+
resource.TestCheckResourceAttr("tencentcloud_tse_cngw_route.cngw_route", "preserve_host", "true"),
60+
resource.TestCheckResourceAttr("tencentcloud_tse_cngw_route.cngw_route", "protocols.#", "1"),
61+
resource.TestCheckResourceAttr("tencentcloud_tse_cngw_route.cngw_route", "route_name", "terraform-route"),
62+
resource.TestCheckResourceAttr("tencentcloud_tse_cngw_route.cngw_route", "service_id", "b6017eaf-2363-481e-9e93-8d65aaf498cd"),
63+
resource.TestCheckResourceAttr("tencentcloud_tse_cngw_route.cngw_route", "strip_path", "false"),
64+
),
65+
},
4866
},
4967
})
5068
}
@@ -114,7 +132,6 @@ const testAccTseCngwRoute = DefaultTseVar + `
114132
115133
resource "tencentcloud_tse_cngw_route" "cngw_route" {
116134
destination_ports = []
117-
force_https = false
118135
gateway_id = var.gateway_id
119136
hosts = [
120137
"192.168.0.1:9090",
@@ -137,3 +154,29 @@ resource "tencentcloud_tse_cngw_route" "cngw_route" {
137154
strip_path = true
138155
}
139156
`
157+
158+
const testAccTseCngwRouteUp = DefaultTseVar + `
159+
160+
resource "tencentcloud_tse_cngw_route" "cngw_route" {
161+
destination_ports = []
162+
gateway_id = var.gateway_id
163+
hosts = [
164+
"192.168.0.1:9091",
165+
]
166+
https_redirect_status_code = 301
167+
paths = [
168+
"/user1",
169+
]
170+
headers {
171+
key = "req"
172+
value = "terraform1"
173+
}
174+
preserve_host = true
175+
protocols = [
176+
"http",
177+
]
178+
route_name = "terraform-route"
179+
service_id = "b6017eaf-2363-481e-9e93-8d65aaf498cd"
180+
strip_path = false
181+
}
182+
`

tencentcloud/resource_tc_tse_cngw_service.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ func resourceTencentCloudTseCngwService() *schema.Resource {
245245
"algorithm": {
246246
Type: schema.TypeString,
247247
Optional: true,
248+
Computed: true,
248249
Description: "load balance algorithm,default: `round-robin`, `least-connections` and `consisten_hashing` also support.",
249250
},
250251
"auto_scaling_group_id": {

tencentcloud/service_tencentcloud_tse.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1217,7 +1217,7 @@ func (me *TseService) CheckTseNativeAPIGatewayGroupStatusById(ctx context.Contex
12171217
return resource.NonRetryableError(fmt.Errorf("group %s not exists", groupId))
12181218
}
12191219

1220-
if *gateway.Status == "Modifying" {
1220+
if *gateway.Status == "Modifying" || *gateway.Status == "UpdatingSpec" {
12211221
return resource.RetryableError(fmt.Errorf("update group status is %v,start retrying ...", *gateway.Status))
12221222
}
12231223
if *gateway.Status == "Running" {
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
---
2+
subcategory: "Tencent Cloud Service Engine(TSE)"
3+
layout: "tencentcloud"
4+
page_title: "TencentCloud: tencentcloud_tse_cngw_group"
5+
sidebar_current: "docs-tencentcloud-resource-tse_cngw_group"
6+
description: |-
7+
Provides a resource to create a tse cngw_group
8+
---
9+
10+
# tencentcloud_tse_cngw_group
11+
12+
Provides a resource to create a tse cngw_group
13+
14+
## Example Usage
15+
16+
```hcl
17+
variable "availability_zone" {
18+
default = "ap-guangzhou-4"
19+
}
20+
21+
resource "tencentcloud_vpc" "vpc" {
22+
cidr_block = "10.0.0.0/16"
23+
name = "tf_tse_vpc"
24+
}
25+
26+
resource "tencentcloud_subnet" "subnet" {
27+
vpc_id = tencentcloud_vpc.vpc.id
28+
availability_zone = var.availability_zone
29+
name = "tf_tse_subnet"
30+
cidr_block = "10.0.1.0/24"
31+
}
32+
33+
resource "tencentcloud_tse_cngw_gateway" "cngw_gateway" {
34+
description = "terraform test1"
35+
enable_cls = true
36+
engine_region = "ap-guangzhou"
37+
feature_version = "STANDARD"
38+
gateway_version = "2.5.1"
39+
ingress_class_name = "tse-nginx-ingress"
40+
internet_max_bandwidth_out = 0
41+
name = "terraform-gateway1"
42+
trade_type = 0
43+
type = "kong"
44+
45+
node_config {
46+
number = 2
47+
specification = "1c2g"
48+
}
49+
50+
vpc_config {
51+
subnet_id = tencentcloud_subnet.subnet.id
52+
vpc_id = tencentcloud_vpc.vpc.id
53+
}
54+
55+
tags = {
56+
"createdBy" = "terraform"
57+
}
58+
}
59+
60+
resource "tencentcloud_tse_cngw_group" "cngw_group" {
61+
description = "terraform desc"
62+
gateway_id = tencentcloud_tse_cngw_gateway.cngw_gateway.id
63+
name = "terraform-group"
64+
subnet_id = tencentcloud_subnet.subnet.id
65+
66+
node_config {
67+
number = 2
68+
specification = "1c2g"
69+
}
70+
}
71+
```
72+
73+
## Argument Reference
74+
75+
The following arguments are supported:
76+
77+
* `gateway_id` - (Required, String) gateway IDonly postpaid gateway supported.
78+
* `name` - (Required, String) gateway group name.
79+
* `node_config` - (Required, List) group node configration.
80+
* `subnet_id` - (Required, String) subnet ID. Assign an IP address to the engine in the VPC subnet. Reference value:- subnet-ahde9me9.
81+
* `description` - (Optional, String) description information of group.
82+
* `internet_config` - (Optional, List) internet configration.
83+
* `internet_max_bandwidth_out` - (Optional, Int) public network outbound traffic bandwidth,[1,2048]Mbps.
84+
85+
The `internet_config` object supports the following:
86+
87+
* `description` - (Optional, String) description of clb.
88+
* `internet_address_version` - (Optional, String) internet type. Reference value:- IPV4 (default value)- IPV6.
89+
* `internet_max_bandwidth_out` - (Optional, Int) public network bandwidth.
90+
* `internet_pay_mode` - (Optional, String) trade type of internet. Reference value:- BANDWIDTH- TRAFFIC (default value).
91+
* `master_zone_id` - (Optional, String) primary availability zone.
92+
* `multi_zone_flag` - (Optional, Bool) Whether load balancing has multiple availability zones.
93+
* `sla_type` - (Optional, String) specification type of clb. Default shared type when this parameter is empty. Reference value:- SLA LCU-supported.
94+
* `slave_zone_id` - (Optional, String) alternate availability zone.
95+
96+
The `node_config` object supports the following:
97+
98+
* `number` - (Required, Int) group node number, 2-50.
99+
* `specification` - (Required, String) group specification, 1c2g|2c4g|4c8g|8c16g.
100+
101+
## Attributes Reference
102+
103+
In addition to all arguments above, the following attributes are exported:
104+
105+
* `id` - ID of the resource.
106+
107+
108+

0 commit comments

Comments
 (0)