Skip to content

Commit 7a0017a

Browse files
authored
[Feat] VPC: Add route table route and subnet associate resources (#3312)
[Feat] VPC: Add route table route and subnet associate resources Summary of the Pull Request Add two new resources for managing VPC route table configurations independently of the route table lifecycle: opentelekomcloud_vpc_route_table_route_v1: manages individual routes within default or custom route tables, supporting all OTC route types and in-place updates opentelekomcloud_vpc_route_table_subnet_associate_v1: manages the association between a subnet and a custom route table Also includes: Friendly error message when creating a route with a destination that already exists (API error VPC.2812), guiding users to terraform import Fix for 400 error in opentelekomcloud_vpc_route_table_v1 Delete when subnets are already disassociated, which occurs when subnet associations are managed by the new _subnet_associate_v1 resource PR Checklist Refers to: #3310, #3311 Tests added/passed. Documentation updated. Schema updated. Release notes added. Acceptance Steps Performed === RUN TestAccVpcRouteTableRouteV1_basic --- PASS: TestAccVpcRouteTableRouteV1_basic === RUN TestAccVpcRouteTableRouteV1_withRouteTable --- PASS: TestAccVpcRouteTableRouteV1_withRouteTable === RUN TestAccVpcRouteTableSubnetAssociateV1_basic --- PASS: TestAccVpcRouteTableSubnetAssociateV1_basic === RUN TestAccVpcRouteTableRouteV1_duplicateDestination --- PASS: TestAccVpcRouteTableRouteV1_duplicateDestination PASS Closes #3310 Closes #3311 Reviewed-by: Anton Sidelnikov Reviewed-by: Muneeb H. Jan <muneebhafeezjan@gmail.com> Reviewed-by: Artem Lifshits
1 parent 2d13d02 commit 7a0017a

9 files changed

+1054
-1
lines changed
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
---
2+
subcategory: "Virtual Private Cloud (VPC)"
3+
layout: "opentelekomcloud"
4+
page_title: "OpenTelekomCloud: opentelekomcloud_vpc_route_table_route_v1"
5+
sidebar_current: "docs-opentelekomcloud-resource-vpc-route-table-route-v1"
6+
description: |-
7+
Manages a VPC Route Table Route resource within OpenTelekomCloud.
8+
---
9+
10+
Up-to-date reference of API arguments for VPC route table you can get at
11+
[documentation portal](https://docs.otc.t-systems.com/virtual-private-cloud/api-ref/apis/route_table/index.html)
12+
13+
# opentelekomcloud_vpc_route_table_route_v1
14+
15+
Manages an individual route within a VPC route table. This resource allows managing
16+
routes independently of the route table lifecycle, including adding routes to the
17+
default route table.
18+
19+
## Example Usage
20+
21+
### Route on Default Route Table
22+
23+
```hcl
24+
resource "opentelekomcloud_vpc_v1" "vpc_1" {
25+
name = "vpc-1"
26+
cidr = "192.168.0.0/16"
27+
}
28+
29+
resource "opentelekomcloud_vpc_v1" "vpc_2" {
30+
name = "vpc-2"
31+
cidr = "172.16.0.0/16"
32+
}
33+
34+
resource "opentelekomcloud_vpc_peering_connection_v2" "peering" {
35+
name = "my_peering"
36+
vpc_id = opentelekomcloud_vpc_v1.vpc_1.id
37+
peer_vpc_id = opentelekomcloud_vpc_v1.vpc_2.id
38+
}
39+
40+
resource "opentelekomcloud_vpc_route_table_route_v1" "route" {
41+
vpc_id = opentelekomcloud_vpc_v1.vpc_1.id
42+
destination = "172.16.0.0/16"
43+
type = "peering"
44+
nexthop = opentelekomcloud_vpc_peering_connection_v2.peering.id
45+
description = "peering route"
46+
}
47+
```
48+
49+
### Route on Custom Route Table
50+
51+
```hcl
52+
resource "opentelekomcloud_vpc_v1" "vpc_1" {
53+
name = "vpc-1"
54+
cidr = "192.168.0.0/16"
55+
}
56+
57+
resource "opentelekomcloud_vpc_v1" "vpc_2" {
58+
name = "vpc-2"
59+
cidr = "172.16.0.0/16"
60+
}
61+
62+
resource "opentelekomcloud_vpc_peering_connection_v2" "peering" {
63+
name = "my_peering"
64+
vpc_id = opentelekomcloud_vpc_v1.vpc_1.id
65+
peer_vpc_id = opentelekomcloud_vpc_v1.vpc_2.id
66+
}
67+
68+
resource "opentelekomcloud_vpc_route_table_v1" "table" {
69+
name = "my_table"
70+
vpc_id = opentelekomcloud_vpc_v1.vpc_1.id
71+
}
72+
73+
resource "opentelekomcloud_vpc_route_table_route_v1" "route" {
74+
vpc_id = opentelekomcloud_vpc_v1.vpc_1.id
75+
route_table_id = opentelekomcloud_vpc_route_table_v1.table.id
76+
destination = "172.16.0.0/16"
77+
type = "peering"
78+
nexthop = opentelekomcloud_vpc_peering_connection_v2.peering.id
79+
description = "peering route on custom table"
80+
}
81+
```
82+
83+
## Argument Reference
84+
85+
The following arguments are supported:
86+
87+
* `region` - (Optional, String, ForceNew) The region in which to create the route.
88+
If omitted, the provider-level region will be used. Changing this creates a new resource.
89+
90+
* `vpc_id` - (Required, String, ForceNew) Specifies the VPC ID that the route table belongs to.
91+
Changing this creates a new resource.
92+
93+
* `destination` - (Required, String, ForceNew) Specifies the destination address in the CIDR notation format,
94+
for example, 192.168.200.0/24. The destination of each route must be unique and cannot overlap
95+
with any subnet in the VPC. Changing this creates a new resource.
96+
97+
* `type` - (Required, String) Specifies the route type. Currently, the value can be:
98+
**ecs**, **eni**, **vip**, **nat**, **peering**, **vpn**, **dc**, **egw**, **er**, **subeni** and **local**
99+
100+
* `nexthop` - (Required, String) Specifies the next hop.
101+
+ If the route type is **ecs**, the value is an ECS instance ID in the VPC.
102+
+ If the route type is **eni**, the value is the extension NIC of an ECS in the VPC.
103+
+ If the route type is **vip**, the value is a virtual IP address.
104+
+ If the route type is **nat**, the value is a NAT gateway ID.
105+
+ If the route type is **peering**, the value is a VPC peering connection ID.
106+
+ If the route type is **vpn**, the value is a VPN gateway ID.
107+
+ If the route type is **dc**, the value is a Direct Connect gateway ID.
108+
+ If the route type is **egw**, the value is a VPC endpoint ID.
109+
+ If the route type is **er**, the value is the ID of an enterprise router.
110+
+ If the route type is **subeni**, the value is the ID of a supplementary network interface.
111+
112+
* `description` - (Optional, String) Specifies the supplementary information about the route.
113+
The value is a string of no more than 255 characters and cannot contain angle brackets (< or >).
114+
115+
* `route_table_id` - (Optional, String, ForceNew) Specifies the route table ID. If omitted, the
116+
default route table of the VPC will be used. Changing this creates a new resource.
117+
118+
## Attribute Reference
119+
120+
In addition to all arguments above, the following attributes are exported:
121+
122+
* `id` - The resource ID in format `{route_table_id}/{destination}`.
123+
* `route_table_name` - The name of the route table.
124+
125+
## Import
126+
127+
Routes can be imported using the route table ID and destination, separated by a slash, e.g.
128+
129+
-> **NOTE:** The import ID contains the route table UUID followed by a `/` and the CIDR destination
130+
(which itself contains a `/`), e.g. `<route_table_id>/<cidr_destination>`.
131+
132+
```
133+
$ terraform import opentelekomcloud_vpc_route_table_route_v1.route 14c6491a-f90a-41aa-a206-f58bbacdb47d/172.16.0.0/16
134+
```
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
---
2+
subcategory: "Virtual Private Cloud (VPC)"
3+
layout: "opentelekomcloud"
4+
page_title: "OpenTelekomCloud: opentelekomcloud_vpc_route_table_subnet_associate_v1"
5+
sidebar_current: "docs-opentelekomcloud-resource-vpc-route-table-subnet-associate-v1"
6+
description: |-
7+
Manages a VPC Route Table Subnet Association resource within OpenTelekomCloud.
8+
---
9+
10+
Up-to-date reference of API arguments for VPC route table you can get at
11+
[documentation portal](https://docs.otc.t-systems.com/virtual-private-cloud/api-ref/apis/route_table/index.html)
12+
13+
# opentelekomcloud_vpc_route_table_subnet_associate_v1
14+
15+
Manages the association between a subnet and a VPC route table.
16+
17+
A subnet is always associated with exactly one route table. Associating a subnet with a
18+
new route table automatically moves it from the previous one. Destroying this resource
19+
disassociates the subnet, which returns it to the VPC's default route table.
20+
21+
~> **NOTE:** When using this resource, the `opentelekomcloud_vpc_route_table_v1` resource must include
22+
`lifecycle { ignore_changes = [subnets] }` to avoid conflicts. Both resources manage subnet associations
23+
on the same route table, and without `ignore_changes`, Terraform will detect a perpetual diff on the
24+
route table's `subnets` attribute.
25+
26+
## Example Usage
27+
28+
```hcl
29+
resource "opentelekomcloud_vpc_v1" "vpc" {
30+
name = "my-vpc"
31+
cidr = "192.168.0.0/16"
32+
}
33+
34+
resource "opentelekomcloud_vpc_subnet_v1" "subnet" {
35+
name = "my-subnet"
36+
cidr = "192.168.0.0/24"
37+
gateway_ip = "192.168.0.1"
38+
vpc_id = opentelekomcloud_vpc_v1.vpc.id
39+
}
40+
41+
resource "opentelekomcloud_vpc_route_table_v1" "table" {
42+
name = "my-table"
43+
vpc_id = opentelekomcloud_vpc_v1.vpc.id
44+
45+
lifecycle {
46+
ignore_changes = [subnets]
47+
}
48+
}
49+
50+
resource "opentelekomcloud_vpc_route_table_subnet_associate_v1" "assoc" {
51+
route_table_id = opentelekomcloud_vpc_route_table_v1.table.id
52+
subnet_id = opentelekomcloud_vpc_subnet_v1.subnet.id
53+
}
54+
```
55+
56+
## Argument Reference
57+
58+
The following arguments are supported:
59+
60+
* `region` - (Optional, String, ForceNew) The region in which to create the association.
61+
If omitted, the provider-level region will be used. Changing this creates a new resource.
62+
63+
* `route_table_id` - (Required, String, ForceNew) Specifies the route table ID to associate the
64+
subnet with. Changing this creates a new resource.
65+
66+
* `subnet_id` - (Required, String, ForceNew) Specifies the subnet ID to associate with the route
67+
table. Changing this creates a new resource.
68+
69+
## Attribute Reference
70+
71+
In addition to all arguments above, the following attributes are exported:
72+
73+
* `id` - The resource ID in format `{route_table_id}/{subnet_id}`.
74+
* `vpc_id` - The VPC ID that the route table belongs to.
75+
76+
## Import
77+
78+
Route table subnet associations can be imported using the route table ID and subnet ID, separated by a slash, e.g.
79+
80+
```
81+
$ terraform import opentelekomcloud_vpc_route_table_subnet_associate_v1.assoc 14c6491a-f90a-41aa-a206-f58bbacdb47d/a1b2c3d4-e5f6-7890-abcd-ef1234567890
82+
```

0 commit comments

Comments
 (0)