Skip to content

fix(vpc): [121657174] tencentcloud_route_table_entry params next_type add new type #3077

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/3077.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/tencentcloud_route_table_entry: `next_type` support new type
```
4 changes: 4 additions & 0 deletions tencentcloud/services/vpc/extension_vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const GATE_WAY_TYPE_NORMAL_CVM = "NORMAL_CVM"
const GATE_WAY_TYPE_EIP = "EIP"
const GATE_WAY_TYPE_CCN = "CCN"
const GATE_WAY_TYPE_LOCAL_GATEWAY = "LOCAL_GATEWAY"
const GATE_WAY_TYPE_INTRANAT = "INTRANAT"
const GATE_WAY_TYPE_USER_CCN = "USER_CCN"

var ALL_GATE_WAY_TYPES = []string{
GATE_WAY_TYPE_CVM,
Expand All @@ -28,6 +30,8 @@ var ALL_GATE_WAY_TYPES = []string{
GATE_WAY_TYPE_EIP,
GATE_WAY_TYPE_CCN,
GATE_WAY_TYPE_LOCAL_GATEWAY,
GATE_WAY_TYPE_INTRANAT,
GATE_WAY_TYPE_USER_CCN,
}

const VPC_SERVICE_TYPE = "vpc"
Expand Down
6 changes: 5 additions & 1 deletion tencentcloud/services/vpc/resource_tc_route_entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ var routeTypeApiMap = map[string]int{
"instance": 9,
"eip": 10,
"local_gateway": 11,
"intranat": 12,
"user_ccn": 13,
}

var RouteTypeApiMap = routeTypeApiMap
Expand All @@ -38,6 +40,8 @@ var routeTypeNewMap = map[string]string{
"instance": "NORMAL_CVM",
"eip": "EIP",
"local_gateway": "LOCAL_GATEWAY",
"intranat": "INTRANAT",
"user_ccn": "USER_CCN",
}

var RouteTypeNewMap = routeTypeNewMap
Expand Down Expand Up @@ -85,7 +89,7 @@ func ResourceTencentCloudRouteEntry() *schema.Resource {
}
return
},
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.",
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.",
},
"next_hub": {
Type: schema.TypeString,
Expand Down
55 changes: 36 additions & 19 deletions tencentcloud/services/vpc/resource_tc_route_table_entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func ResourceTencentCloudVpcRouteEntry() *schema.Resource {
Required: true,
ForceNew: true,
ValidateFunc: tccommon.ValidateAllowedStringValue(ALL_GATE_WAY_TYPES),
Description: "Type of next-hop. Valid values: `CVM`, `VPN`, `DIRECTCONNECT`, `PEERCONNECTION`, `HAVIP`, `NAT`, `NORMAL_CVM`, `EIP` and `LOCAL_GATEWAY`.",
Description: "Type of next-hop. Valid values: `CVM`, `VPN`, `DIRECTCONNECT`, `PEERCONNECTION`, `HAVIP`, `NAT`, `NORMAL_CVM`, `EIP`, `LOCAL_GATEWAY`, `INTRANAT` and `USER_CCN`.",
},
"next_hub": {
Type: schema.TypeString,
Expand Down Expand Up @@ -78,10 +78,11 @@ func ResourceTencentCloudVpcRouteEntry() *schema.Resource {
func resourceTencentCloudVpcRouteEntryCreate(d *schema.ResourceData, meta interface{}) error {
defer tccommon.LogElapsed("resource.tencentcloud_route_table_entry.create")()

logId := tccommon.GetLogId(tccommon.ContextNil)
ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId)

service := VpcService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
var (
logId = tccommon.GetLogId(tccommon.ContextNil)
ctx = context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
service = VpcService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
)

var (
description = ""
Expand All @@ -95,20 +96,24 @@ func resourceTencentCloudVpcRouteEntryCreate(d *schema.ResourceData, meta interf
if temp, ok := d.GetOk("description"); ok {
description = temp.(string)
}

if temp, ok := d.GetOk("route_table_id"); ok {
routeTableId = temp.(string)
}

if temp, ok := d.GetOk("destination_cidr_block"); ok {
destinationCidrBlock = temp.(string)
}

if temp, ok := d.GetOk("next_type"); ok {
nextType = temp.(string)
}

if temp, ok := d.GetOk("next_hub"); ok {
nextHub = temp.(string)
}

if temp, ok := d.GetOk("disabled"); ok {
if temp, ok := d.GetOkExists("disabled"); ok {
disabled = temp.(bool)
}

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

// route cannot disable on create
entryId, err := service.CreateRoutes(ctx, routeTableId, destinationCidrBlock, nextType, nextHub, description, true)

if err != nil {
return err
}
Expand All @@ -146,15 +150,17 @@ func resourceTencentCloudVpcRouteEntryRead(d *schema.ResourceData, meta interfac
defer tccommon.LogElapsed("resource.tencentcloud_route_table_entry.read")()
defer tccommon.InconsistentCheck(d, meta)()

logId := tccommon.GetLogId(tccommon.ContextNil)
ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId)

service := VpcService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
var (
logId = tccommon.GetLogId(tccommon.ContextNil)
ctx = context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
service = VpcService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
)

items := strings.Split(d.Id(), ".")
if len(items) != 2 {
return fmt.Errorf("entry id be destroyed, we can not get route table id")
}

err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError {
info, has, e := service.DescribeRouteTable(ctx, items[1])
if e != nil {
Expand Down Expand Up @@ -183,20 +189,27 @@ func resourceTencentCloudVpcRouteEntryRead(d *schema.ResourceData, meta interfac
return nil
}
}

d.SetId("")
return nil
})

if err != nil {
return err
}

return nil
}

func resourceTencentCloudVpcRouteEntryUpdate(d *schema.ResourceData, meta interface{}) error {
logId := tccommon.GetLogId(tccommon.ContextNil)
ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
client := meta.(tccommon.ProviderMeta).GetAPIV3Conn()
service := VpcService{client}
defer tccommon.LogElapsed("resource.tencentcloud_route_table_entry.update")()

var (
logId = tccommon.GetLogId(tccommon.ContextNil)
ctx = context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
client = meta.(tccommon.ProviderMeta).GetAPIV3Conn()
service = VpcService{client}
)

items := strings.Split(d.Id(), ".")
if len(items) != 2 {
Expand All @@ -216,16 +229,18 @@ func resourceTencentCloudVpcRouteEntryUpdate(d *schema.ResourceData, meta interf
return err
}
}

return resourceTencentCloudVpcRouteEntryRead(d, meta)
}

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

logId := tccommon.GetLogId(tccommon.ContextNil)
ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId)

service := VpcService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
var (
logId = tccommon.GetLogId(tccommon.ContextNil)
ctx = context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
service = VpcService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
)

items := strings.Split(d.Id(), ".")
if len(items) != 2 {
Expand All @@ -245,8 +260,10 @@ func resourceTencentCloudVpcRouteEntryDelete(d *schema.ResourceData, meta interf
return nil
}
}

return resource.RetryableError(err)
}

return nil
})

Expand Down
16 changes: 8 additions & 8 deletions tencentcloud/services/vpc/resource_tc_route_table_entry.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ resource "tencentcloud_vpc" "vpc" {
cidr_block = "10.0.0.0/16"
}

# create route table
resource "tencentcloud_route_table" "example" {
vpc_id = tencentcloud_vpc.vpc.id
name = "tf-example"
}

# create subnet
resource "tencentcloud_subnet" "subnet" {
vpc_id = tencentcloud_vpc.vpc.id
Expand All @@ -22,19 +28,13 @@ resource "tencentcloud_subnet" "subnet" {
route_table_id = tencentcloud_route_table.example.id
}

# create route table
resource "tencentcloud_route_table" "example" {
vpc_id = tencentcloud_vpc.vpc.id
name = "tf-example"
}

# create route table entry
resource "tencentcloud_route_table_entry" "example" {
route_table_id = tencentcloud_route_table.example.id
destination_cidr_block = "10.4.4.0/24"
destination_cidr_block = "10.12.12.0/24"
next_type = "EIP"
next_hub = "0"
description = "describe"
description = "Terraform test."
}

# output
Expand Down
63 changes: 38 additions & 25 deletions tencentcloud/services/vpc/service_tencentcloud_vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,7 @@ func (me *VpcService) CreateRoutes(ctx context.Context,

logId := tccommon.GetLogId(ctx)
request := vpc.NewCreateRoutesRequest()
response := vpc.NewCreateRoutesResponse()
defer func() {
if errRet != nil {
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n",
Expand All @@ -1155,6 +1156,7 @@ func (me *VpcService) CreateRoutes(ctx context.Context,
errRet = fmt.Errorf("CreateRoutes can not invoke by empty routeTableId.")
return
}

request.RouteTableId = &routeTableId
var route vpc.Route
route.DestinationCidrBlock = &destinationCidrBlock
Expand All @@ -1163,22 +1165,23 @@ func (me *VpcService) CreateRoutes(ctx context.Context,
route.GatewayId = &nextHub
route.Enabled = &enabled
request.Routes = []*vpc.Route{&route}
ratelimit.Check(request.GetAction())
response, err := me.client.UseVpcClient().CreateRoutes(request)
errRet = err
if err == nil {
log.Printf("[DEBUG]%s api[%s] , request body [%s], response body[%s]\n",
logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())
} else {
return
}
err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
ratelimit.Check(request.GetAction())
result, e := me.client.UseVpcClient().CreateRoutes(request)
if e != nil {
return tccommon.RetryError(e)
}

if response == nil {
return
}
if result == nil || result.Response == nil || result.Response.RouteTableSet == nil {
return resource.NonRetryableError(fmt.Errorf("CreateRoutes failed, Response is nil."))
}

response = result
return nil
})

if *response.Response.TotalCount != 1 {
errRet = fmt.Errorf("CreateRoutes return %d routeTable. but we only request 1.\n", *response.Response.TotalCount)
if err != nil {
errRet = err
return
}

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

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

ratelimit.Check(request.GetAction())
response, err := me.client.UseVpcClient().EnableRoutes(request)
err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
ratelimit.Check(request.GetAction())
response, e := me.client.UseVpcClient().EnableRoutes(request)
if e != nil {
return tccommon.RetryError(e)
}

log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())
return nil
})

if err != nil {
errRet = err
return
}

log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n",
logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())

return
}
func (me *VpcService) DisableRoutes(ctx context.Context, request *vpc.DisableRoutesRequest) (errRet error) {
Expand All @@ -1242,17 +1250,22 @@ func (me *VpcService) DisableRoutes(ctx context.Context, request *vpc.DisableRou
}
}()

ratelimit.Check(request.GetAction())
response, err := me.client.UseVpcClient().DisableRoutes(request)
err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
ratelimit.Check(request.GetAction())
response, e := me.client.UseVpcClient().DisableRoutes(request)
if e != nil {
return tccommon.RetryError(e)
}

log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())
return nil
})

if err != nil {
errRet = err
return
}

log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n",
logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())

return
}
func (me *VpcService) CreateSecurityGroup(ctx context.Context, name, desc string, projectId *int, tags map[string]string) (id string, err error) {
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/route_entry.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ The following arguments are supported:

* `cidr_block` - (Required, String, ForceNew) The RouteEntry's target network segment.
* `next_hub` - (Required, String, ForceNew) The route entry's next hub. CVM instance ID or VPC router interface ID.
* `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.
* `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.
* `route_table_id` - (Required, String, ForceNew) The ID of the route table.
* `vpc_id` - (Required, String, ForceNew) The VPC ID.

Expand Down
Loading
Loading