Skip to content

Commit 902b9cf

Browse files
authored
fix(vpc): [121657174] tencentcloud_route_table_entry params next_type add new type (#3077)
* add * add
1 parent 784954e commit 902b9cf

8 files changed

+104
-63
lines changed

.changelog/3077.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_route_table_entry: `next_type` support new type
3+
```

tencentcloud/services/vpc/extension_vpc.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ const GATE_WAY_TYPE_NORMAL_CVM = "NORMAL_CVM"
1515
const GATE_WAY_TYPE_EIP = "EIP"
1616
const GATE_WAY_TYPE_CCN = "CCN"
1717
const GATE_WAY_TYPE_LOCAL_GATEWAY = "LOCAL_GATEWAY"
18+
const GATE_WAY_TYPE_INTRANAT = "INTRANAT"
19+
const GATE_WAY_TYPE_USER_CCN = "USER_CCN"
1820

1921
var ALL_GATE_WAY_TYPES = []string{
2022
GATE_WAY_TYPE_CVM,
@@ -28,6 +30,8 @@ var ALL_GATE_WAY_TYPES = []string{
2830
GATE_WAY_TYPE_EIP,
2931
GATE_WAY_TYPE_CCN,
3032
GATE_WAY_TYPE_LOCAL_GATEWAY,
33+
GATE_WAY_TYPE_INTRANAT,
34+
GATE_WAY_TYPE_USER_CCN,
3135
}
3236

3337
const VPC_SERVICE_TYPE = "vpc"

tencentcloud/services/vpc/resource_tc_route_entry.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ var routeTypeApiMap = map[string]int{
2323
"instance": 9,
2424
"eip": 10,
2525
"local_gateway": 11,
26+
"intranat": 12,
27+
"user_ccn": 13,
2628
}
2729

2830
var RouteTypeApiMap = routeTypeApiMap
@@ -38,6 +40,8 @@ var routeTypeNewMap = map[string]string{
3840
"instance": "NORMAL_CVM",
3941
"eip": "EIP",
4042
"local_gateway": "LOCAL_GATEWAY",
43+
"intranat": "INTRANAT",
44+
"user_ccn": "USER_CCN",
4145
}
4246

4347
var RouteTypeNewMap = routeTypeNewMap
@@ -85,7 +89,7 @@ func ResourceTencentCloudRouteEntry() *schema.Resource {
8589
}
8690
return
8791
},
88-
Description: "The next hop type. Valid values: `public_gateway`,`vpn_gateway`,`sslvpn_gateway`,`dc_gateway`,`peering_connection`,`nat_gateway`,`havip`,`local_gateway` and `instance`. `instance` points to CVM Instance.",
92+
Description: "The next hop type. Valid values: `public_gateway`,`vpn_gateway`,`sslvpn_gateway`,`dc_gateway`,`peering_connection`,`nat_gateway`,`havip`,`local_gateway`, `intranat`, `user_ccn` and `instance`. `instance` points to CVM Instance.",
8993
},
9094
"next_hub": {
9195
Type: schema.TypeString,

tencentcloud/services/vpc/resource_tc_route_table_entry.go

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func ResourceTencentCloudVpcRouteEntry() *schema.Resource {
4646
Required: true,
4747
ForceNew: true,
4848
ValidateFunc: tccommon.ValidateAllowedStringValue(ALL_GATE_WAY_TYPES),
49-
Description: "Type of next-hop. Valid values: `CVM`, `VPN`, `DIRECTCONNECT`, `PEERCONNECTION`, `HAVIP`, `NAT`, `NORMAL_CVM`, `EIP` and `LOCAL_GATEWAY`.",
49+
Description: "Type of next-hop. Valid values: `CVM`, `VPN`, `DIRECTCONNECT`, `PEERCONNECTION`, `HAVIP`, `NAT`, `NORMAL_CVM`, `EIP`, `LOCAL_GATEWAY`, `INTRANAT` and `USER_CCN`.",
5050
},
5151
"next_hub": {
5252
Type: schema.TypeString,
@@ -78,10 +78,11 @@ func ResourceTencentCloudVpcRouteEntry() *schema.Resource {
7878
func resourceTencentCloudVpcRouteEntryCreate(d *schema.ResourceData, meta interface{}) error {
7979
defer tccommon.LogElapsed("resource.tencentcloud_route_table_entry.create")()
8080

81-
logId := tccommon.GetLogId(tccommon.ContextNil)
82-
ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
83-
84-
service := VpcService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
81+
var (
82+
logId = tccommon.GetLogId(tccommon.ContextNil)
83+
ctx = context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
84+
service = VpcService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
85+
)
8586

8687
var (
8788
description = ""
@@ -95,20 +96,24 @@ func resourceTencentCloudVpcRouteEntryCreate(d *schema.ResourceData, meta interf
9596
if temp, ok := d.GetOk("description"); ok {
9697
description = temp.(string)
9798
}
99+
98100
if temp, ok := d.GetOk("route_table_id"); ok {
99101
routeTableId = temp.(string)
100102
}
103+
101104
if temp, ok := d.GetOk("destination_cidr_block"); ok {
102105
destinationCidrBlock = temp.(string)
103106
}
107+
104108
if temp, ok := d.GetOk("next_type"); ok {
105109
nextType = temp.(string)
106110
}
111+
107112
if temp, ok := d.GetOk("next_hub"); ok {
108113
nextHub = temp.(string)
109114
}
110115

111-
if temp, ok := d.GetOk("disabled"); ok {
116+
if temp, ok := d.GetOkExists("disabled"); ok {
112117
disabled = temp.(bool)
113118
}
114119

@@ -122,7 +127,6 @@ func resourceTencentCloudVpcRouteEntryCreate(d *schema.ResourceData, meta interf
122127

123128
// route cannot disable on create
124129
entryId, err := service.CreateRoutes(ctx, routeTableId, destinationCidrBlock, nextType, nextHub, description, true)
125-
126130
if err != nil {
127131
return err
128132
}
@@ -146,15 +150,17 @@ func resourceTencentCloudVpcRouteEntryRead(d *schema.ResourceData, meta interfac
146150
defer tccommon.LogElapsed("resource.tencentcloud_route_table_entry.read")()
147151
defer tccommon.InconsistentCheck(d, meta)()
148152

149-
logId := tccommon.GetLogId(tccommon.ContextNil)
150-
ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
151-
152-
service := VpcService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
153+
var (
154+
logId = tccommon.GetLogId(tccommon.ContextNil)
155+
ctx = context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
156+
service = VpcService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
157+
)
153158

154159
items := strings.Split(d.Id(), ".")
155160
if len(items) != 2 {
156161
return fmt.Errorf("entry id be destroyed, we can not get route table id")
157162
}
163+
158164
err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError {
159165
info, has, e := service.DescribeRouteTable(ctx, items[1])
160166
if e != nil {
@@ -183,20 +189,27 @@ func resourceTencentCloudVpcRouteEntryRead(d *schema.ResourceData, meta interfac
183189
return nil
184190
}
185191
}
192+
186193
d.SetId("")
187194
return nil
188195
})
196+
189197
if err != nil {
190198
return err
191199
}
200+
192201
return nil
193202
}
194203

195204
func resourceTencentCloudVpcRouteEntryUpdate(d *schema.ResourceData, meta interface{}) error {
196-
logId := tccommon.GetLogId(tccommon.ContextNil)
197-
ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
198-
client := meta.(tccommon.ProviderMeta).GetAPIV3Conn()
199-
service := VpcService{client}
205+
defer tccommon.LogElapsed("resource.tencentcloud_route_table_entry.update")()
206+
207+
var (
208+
logId = tccommon.GetLogId(tccommon.ContextNil)
209+
ctx = context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
210+
client = meta.(tccommon.ProviderMeta).GetAPIV3Conn()
211+
service = VpcService{client}
212+
)
200213

201214
items := strings.Split(d.Id(), ".")
202215
if len(items) != 2 {
@@ -216,16 +229,18 @@ func resourceTencentCloudVpcRouteEntryUpdate(d *schema.ResourceData, meta interf
216229
return err
217230
}
218231
}
232+
219233
return resourceTencentCloudVpcRouteEntryRead(d, meta)
220234
}
221235

222236
func resourceTencentCloudVpcRouteEntryDelete(d *schema.ResourceData, meta interface{}) error {
223237
defer tccommon.LogElapsed("resource.tencentcloud_route_table_entry.delete")()
224238

225-
logId := tccommon.GetLogId(tccommon.ContextNil)
226-
ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
227-
228-
service := VpcService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
239+
var (
240+
logId = tccommon.GetLogId(tccommon.ContextNil)
241+
ctx = context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
242+
service = VpcService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
243+
)
229244

230245
items := strings.Split(d.Id(), ".")
231246
if len(items) != 2 {
@@ -245,8 +260,10 @@ func resourceTencentCloudVpcRouteEntryDelete(d *schema.ResourceData, meta interf
245260
return nil
246261
}
247262
}
263+
248264
return resource.RetryableError(err)
249265
}
266+
250267
return nil
251268
})
252269

tencentcloud/services/vpc/resource_tc_route_table_entry.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ resource "tencentcloud_vpc" "vpc" {
1313
cidr_block = "10.0.0.0/16"
1414
}
1515
16+
# create route table
17+
resource "tencentcloud_route_table" "example" {
18+
vpc_id = tencentcloud_vpc.vpc.id
19+
name = "tf-example"
20+
}
21+
1622
# create subnet
1723
resource "tencentcloud_subnet" "subnet" {
1824
vpc_id = tencentcloud_vpc.vpc.id
@@ -22,19 +28,13 @@ resource "tencentcloud_subnet" "subnet" {
2228
route_table_id = tencentcloud_route_table.example.id
2329
}
2430
25-
# create route table
26-
resource "tencentcloud_route_table" "example" {
27-
vpc_id = tencentcloud_vpc.vpc.id
28-
name = "tf-example"
29-
}
30-
3131
# create route table entry
3232
resource "tencentcloud_route_table_entry" "example" {
3333
route_table_id = tencentcloud_route_table.example.id
34-
destination_cidr_block = "10.4.4.0/24"
34+
destination_cidr_block = "10.12.12.0/24"
3535
next_type = "EIP"
3636
next_hub = "0"
37-
description = "describe"
37+
description = "Terraform test."
3838
}
3939
4040
# output

tencentcloud/services/vpc/service_tencentcloud_vpc.go

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,7 @@ func (me *VpcService) CreateRoutes(ctx context.Context,
11441144

11451145
logId := tccommon.GetLogId(ctx)
11461146
request := vpc.NewCreateRoutesRequest()
1147+
response := vpc.NewCreateRoutesResponse()
11471148
defer func() {
11481149
if errRet != nil {
11491150
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n",
@@ -1155,6 +1156,7 @@ func (me *VpcService) CreateRoutes(ctx context.Context,
11551156
errRet = fmt.Errorf("CreateRoutes can not invoke by empty routeTableId.")
11561157
return
11571158
}
1159+
11581160
request.RouteTableId = &routeTableId
11591161
var route vpc.Route
11601162
route.DestinationCidrBlock = &destinationCidrBlock
@@ -1163,22 +1165,23 @@ func (me *VpcService) CreateRoutes(ctx context.Context,
11631165
route.GatewayId = &nextHub
11641166
route.Enabled = &enabled
11651167
request.Routes = []*vpc.Route{&route}
1166-
ratelimit.Check(request.GetAction())
1167-
response, err := me.client.UseVpcClient().CreateRoutes(request)
1168-
errRet = err
1169-
if err == nil {
1170-
log.Printf("[DEBUG]%s api[%s] , request body [%s], response body[%s]\n",
1171-
logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())
1172-
} else {
1173-
return
1174-
}
1168+
err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
1169+
ratelimit.Check(request.GetAction())
1170+
result, e := me.client.UseVpcClient().CreateRoutes(request)
1171+
if e != nil {
1172+
return tccommon.RetryError(e)
1173+
}
11751174

1176-
if response == nil {
1177-
return
1178-
}
1175+
if result == nil || result.Response == nil || result.Response.RouteTableSet == nil {
1176+
return resource.NonRetryableError(fmt.Errorf("CreateRoutes failed, Response is nil."))
1177+
}
1178+
1179+
response = result
1180+
return nil
1181+
})
11791182

1180-
if *response.Response.TotalCount != 1 {
1181-
errRet = fmt.Errorf("CreateRoutes return %d routeTable. but we only request 1.\n", *response.Response.TotalCount)
1183+
if err != nil {
1184+
errRet = err
11821185
return
11831186
}
11841187

@@ -1187,7 +1190,7 @@ func (me *VpcService) CreateRoutes(ctx context.Context,
11871190
return
11881191
}
11891192

1190-
if len(response.Response.RouteTableSet[0].RouteSet) != 1 {
1193+
if response.Response.RouteTableSet[0].RouteSet != nil && len(response.Response.RouteTableSet[0].RouteSet) != 1 {
11911194
errRet = fmt.Errorf("CreateRoutes return %d routeTableSet info. but we only create 1.\n", len(response.Response.RouteTableSet[0].RouteSet))
11921195
return
11931196
}
@@ -1220,17 +1223,22 @@ func (me *VpcService) EnableRoutes(ctx context.Context, request *vpc.EnableRoute
12201223
}
12211224
}()
12221225

1223-
ratelimit.Check(request.GetAction())
1224-
response, err := me.client.UseVpcClient().EnableRoutes(request)
1226+
err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
1227+
ratelimit.Check(request.GetAction())
1228+
response, e := me.client.UseVpcClient().EnableRoutes(request)
1229+
if e != nil {
1230+
return tccommon.RetryError(e)
1231+
}
1232+
1233+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())
1234+
return nil
1235+
})
12251236

12261237
if err != nil {
12271238
errRet = err
12281239
return
12291240
}
12301241

1231-
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n",
1232-
logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())
1233-
12341242
return
12351243
}
12361244
func (me *VpcService) DisableRoutes(ctx context.Context, request *vpc.DisableRoutesRequest) (errRet error) {
@@ -1242,17 +1250,22 @@ func (me *VpcService) DisableRoutes(ctx context.Context, request *vpc.DisableRou
12421250
}
12431251
}()
12441252

1245-
ratelimit.Check(request.GetAction())
1246-
response, err := me.client.UseVpcClient().DisableRoutes(request)
1253+
err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
1254+
ratelimit.Check(request.GetAction())
1255+
response, e := me.client.UseVpcClient().DisableRoutes(request)
1256+
if e != nil {
1257+
return tccommon.RetryError(e)
1258+
}
1259+
1260+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())
1261+
return nil
1262+
})
12471263

12481264
if err != nil {
12491265
errRet = err
12501266
return
12511267
}
12521268

1253-
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n",
1254-
logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())
1255-
12561269
return
12571270
}
12581271
func (me *VpcService) CreateSecurityGroup(ctx context.Context, name, desc string, projectId *int, tags map[string]string) (id string, err error) {

website/docs/r/route_entry.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ The following arguments are supported:
4949

5050
* `cidr_block` - (Required, String, ForceNew) The RouteEntry's target network segment.
5151
* `next_hub` - (Required, String, ForceNew) The route entry's next hub. CVM instance ID or VPC router interface ID.
52-
* `next_type` - (Required, String, ForceNew) The next hop type. Valid values: `public_gateway`,`vpn_gateway`,`sslvpn_gateway`,`dc_gateway`,`peering_connection`,`nat_gateway`,`havip`,`local_gateway` and `instance`. `instance` points to CVM Instance.
52+
* `next_type` - (Required, String, ForceNew) The next hop type. Valid values: `public_gateway`,`vpn_gateway`,`sslvpn_gateway`,`dc_gateway`,`peering_connection`,`nat_gateway`,`havip`,`local_gateway`, `intranat`, `user_ccn` and `instance`. `instance` points to CVM Instance.
5353
* `route_table_id` - (Required, String, ForceNew) The ID of the route table.
5454
* `vpc_id` - (Required, String, ForceNew) The VPC ID.
5555

0 commit comments

Comments
 (0)