Skip to content

fix(vpc): [119554452] tencentcloud_route_table_entry fix creation failure #2808

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 3 commits into from
Sep 5, 2024
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/2808.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/tencentcloud_route_table_entry: fix creation failure
```
4 changes: 2 additions & 2 deletions tencentcloud/services/vpc/resource_tc_route_table_entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,13 @@ func resourceTencentCloudVpcRouteEntryCreate(d *schema.ResourceData, meta interf
request := vpc.NewDisableRoutesRequest()
request.RouteTableId = &routeTableId
request.RouteIds = []*uint64{helper.Int64Uint64(entryId)}
err := service.DisableRoutes(ctx, request)
err = service.DisableRoutes(ctx, request)
if err != nil {
return err
}
}

return nil
return resourceTencentCloudVpcRouteEntryRead(d, meta)
}

func resourceTencentCloudVpcRouteEntryRead(d *schema.ResourceData, meta interface{}) error {
Expand Down
37 changes: 21 additions & 16 deletions tencentcloud/services/vpc/resource_tc_route_table_entry.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,42 @@ Example Usage

```hcl
variable "availability_zone" {
default = "na-siliconvalley-1"
default = "ap-guangzhou-4"
}

resource "tencentcloud_vpc" "foo" {
name = "ci-temp-test"
# create vpc
resource "tencentcloud_vpc" "vpc" {
name = "vpc"
cidr_block = "10.0.0.0/16"
}

resource "tencentcloud_subnet" "foo" {
vpc_id = tencentcloud_vpc.foo.id
name = "terraform test subnet"
# create subnet
resource "tencentcloud_subnet" "subnet" {
vpc_id = tencentcloud_vpc.vpc.id
name = "subnet"
cidr_block = "10.0.12.0/24"
availability_zone = var.availability_zone
route_table_id = tencentcloud_route_table.foo.id
route_table_id = tencentcloud_route_table.example.id
}

resource "tencentcloud_route_table" "foo" {
vpc_id = tencentcloud_vpc.foo.id
name = "ci-temp-test-rt"
# create route table
resource "tencentcloud_route_table" "example" {
vpc_id = tencentcloud_vpc.vpc.id
name = "tf-example"
}

resource "tencentcloud_route_table_entry" "instance" {
route_table_id = tencentcloud_route_table.foo.id
# 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"
next_type = "EIP"
next_hub = "0"
description = "ci-test-route-table-entry"
description = "describe"
}

# output
output "item_id" {
value = tencentcloud_route_table_entry.instance.route_item_id
value = tencentcloud_route_table_entry.example.route_item_id
}
```

Expand All @@ -43,5 +48,5 @@ Import
Route table entry can be imported using the id, e.g.

```
$ terraform import tencentcloud_route_table_entry.foo 83517.rtb-mlhpg09u
```
$ terraform import tencentcloud_route_table_entry.example 3065857.rtb-b050fg94
```
39 changes: 14 additions & 25 deletions tencentcloud/services/vpc/service_tencentcloud_vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"strconv"
"strings"
"sync"
"time"

tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common"

Expand Down Expand Up @@ -1174,36 +1173,26 @@ func (me *VpcService) CreateRoutes(ctx context.Context,
return
}

entryId, errRet = me.GetRouteId(ctx, routeTableId, destinationCidrBlock, nextType, nextHub, description)

if errRet != nil {
time.Sleep(3 * time.Second)
entryId, errRet = me.GetRouteId(ctx, routeTableId, destinationCidrBlock, nextType, nextHub, description)
if response == nil {
return
}

if errRet != nil {
time.Sleep(5 * time.Second)
entryId, errRet = me.GetRouteId(ctx, routeTableId, destinationCidrBlock, nextType, nextHub, description)
if *response.Response.TotalCount != 1 {
errRet = fmt.Errorf("CreateRoutes return %d routeTable. but we only request 1.\n", *response.Response.TotalCount)
return
}

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

if len(response.Response.RouteTableSet) != 1 {
errRet = fmt.Errorf("CreateRoutes return %d routeTable info . but we only request 1.", len(response.Response.RouteTableSet))
return
}
if len(response.Response.RouteTableSet) != 1 {
errRet = fmt.Errorf("CreateRoutes return %d routeTable info. but we only request 1.\n", len(response.Response.RouteTableSet))
return
}

if len(response.Response.RouteTableSet[0].RouteSet) != 1 {
errRet = fmt.Errorf("CreateRoutes return %d routeTableSet info . but we only create 1.", len(response.Response.RouteTableSet[0].RouteSet))
return
}
if 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
}

entryId = int64(*response.Response.RouteTableSet[0].RouteSet[0].RouteId)
*/
entryId = int64(*response.Response.RouteTableSet[0].RouteSet[0].RouteId)

return
}
Expand Down
35 changes: 20 additions & 15 deletions website/docs/r/route_table_entry.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,42 @@ Provides a resource to create an entry of a routing table.

```hcl
variable "availability_zone" {
default = "na-siliconvalley-1"
default = "ap-guangzhou-4"
}

resource "tencentcloud_vpc" "foo" {
name = "ci-temp-test"
# create vpc
resource "tencentcloud_vpc" "vpc" {
name = "vpc"
cidr_block = "10.0.0.0/16"
}

resource "tencentcloud_subnet" "foo" {
vpc_id = tencentcloud_vpc.foo.id
name = "terraform test subnet"
# create subnet
resource "tencentcloud_subnet" "subnet" {
vpc_id = tencentcloud_vpc.vpc.id
name = "subnet"
cidr_block = "10.0.12.0/24"
availability_zone = var.availability_zone
route_table_id = tencentcloud_route_table.foo.id
route_table_id = tencentcloud_route_table.example.id
}

resource "tencentcloud_route_table" "foo" {
vpc_id = tencentcloud_vpc.foo.id
name = "ci-temp-test-rt"
# create route table
resource "tencentcloud_route_table" "example" {
vpc_id = tencentcloud_vpc.vpc.id
name = "tf-example"
}

resource "tencentcloud_route_table_entry" "instance" {
route_table_id = tencentcloud_route_table.foo.id
# 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"
next_type = "EIP"
next_hub = "0"
description = "ci-test-route-table-entry"
description = "describe"
}

# output
output "item_id" {
value = tencentcloud_route_table_entry.instance.route_item_id
value = tencentcloud_route_table_entry.example.route_item_id
}
```

Expand Down Expand Up @@ -73,6 +78,6 @@ In addition to all arguments above, the following attributes are exported:
Route table entry can be imported using the id, e.g.

```
$ terraform import tencentcloud_route_table_entry.foo 83517.rtb-mlhpg09u
$ terraform import tencentcloud_route_table_entry.example 3065857.rtb-b050fg94
```

Loading