Skip to content

Commit d3981ac

Browse files
authored
Merge pull request #3 from clouddrove/internal-274-a
Route Table Addition
2 parents 4cd0276 + b3434b7 commit d3981ac

File tree

10 files changed

+165
-45
lines changed

10 files changed

+165
-45
lines changed

README.yaml

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@ usage: |-
5252
default_name_subnet = true
5353
subnet_names = ["subnet1", "subnet2"]
5454
subnet_prefixes = ["10.0.1.0/24", "10.0.2.0/24"]
55+
56+
# route_table
57+
enable_route_table = false
58+
routes = [
59+
{
60+
name = "rt-test"
61+
address_prefix = "0.0.0.0/0"
62+
next_hop_type = "Internet"
63+
}
64+
]
5565
}
5666
```
5767
### Name_Specific Subnet
@@ -67,11 +77,21 @@ usage: |-
6777
6878
#subnet
6979
specific_name_subnet = true
70-
specific_subnet_names = "GatewaySubnet"
80+
specific_subnet_names = "SpecificSubnet"
7181
subnet_prefixes = ["10.0.1.0/24"]
82+
83+
# route_table
84+
enable_route_table = false
85+
routes = [
86+
{
87+
name = "rt-test"
88+
address_prefix = "0.0.0.0/0"
89+
next_hop_type = "Internet"
90+
}
91+
]
7292
}
7393
```
74-
### Nat_Gateway_Subnet
94+
### Nat_Gateway Subnet
7595
```hcl
7696
module "name_specific_subnet" {
7797
source = "clouddrove/subnet/azure"
@@ -87,5 +107,15 @@ usage: |-
87107
create_nat_gateway = true
88108
subnet_names = ["subnet1", "subnet2"]
89109
subnet_prefixes = ["10.0.1.0/24", "10.0.2.0/24"]
110+
111+
# route_table
112+
enable_route_table = false
113+
routes = [
114+
{
115+
name = "rt-test"
116+
address_prefix = "0.0.0.0/0"
117+
next_hop_type = "Internet"
118+
}
119+
]
90120
}
91121
```

_example/default_subnet/example.tf

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ module "resource_group" {
1313
}
1414

1515
module "vnet" {
16-
source = "clouddrove/virtual-network/azure"
17-
version = "1.0.3"
16+
source = "clouddrove/vnet/azure"
17+
version = "1.0.0"
1818

1919
name = "app"
2020
environment = "test"
@@ -23,17 +23,6 @@ module "vnet" {
2323
location = module.resource_group.resource_group_location
2424
address_space = "10.0.0.0/16"
2525
enable_ddos_pp = false
26-
27-
28-
# routes
29-
enabled_route_table = false
30-
routes = [
31-
{
32-
name = "rt-test"
33-
address_prefix = "0.0.0.0/0"
34-
next_hop_type = "Internet"
35-
}
36-
]
3726
}
3827

3928
module "subnet" {
@@ -50,4 +39,14 @@ module "subnet" {
5039
default_name_subnet = true
5140
subnet_names = ["subnet1", "subnet2"]
5241
subnet_prefixes = ["10.0.1.0/24", "10.0.2.0/24"]
42+
43+
# route_table
44+
enable_route_table = false
45+
routes = [
46+
{
47+
name = "rt-test"
48+
address_prefix = "0.0.0.0/0"
49+
next_hop_type = "Internet"
50+
}
51+
]
5352
}

_example/default_subnet/output.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,14 @@ output "virtual_network_name" {
2121
output "address_prefixes" {
2222
description = "The address prefixes for the subnet."
2323
value = module.subnet.default_subnet_address_prefixes
24+
}
25+
26+
output "route_table_id" {
27+
description = "The Route Table ID."
28+
value = module.subnet.route_table_id
29+
}
30+
31+
output "route_table_associated_subnets" {
32+
description = "The collection of Subnets associated with this route table."
33+
value = module.subnet.*.route_table_associated_subnets[0]
2434
}

_example/name_specific_subnet/example.tf renamed to _example/name-specific_subnet/example.tf

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ module "resource_group" {
1313
}
1414

1515
module "vnet" {
16-
source = "clouddrove/virtual-network/azure"
17-
version = "1.0.3"
16+
source = "clouddrove/vnet/azure"
17+
version = "1.0.0"
1818

1919
name = "app"
2020
environment = "test"
@@ -23,17 +23,6 @@ module "vnet" {
2323
location = module.resource_group.resource_group_location
2424
address_space = "10.0.0.0/16"
2525
enable_ddos_pp = false
26-
27-
28-
# routes
29-
enabled_route_table = false
30-
routes = [
31-
{
32-
name = "rt-test"
33-
address_prefix = "0.0.0.0/0"
34-
next_hop_type = "Internet"
35-
}
36-
]
3726
}
3827

3928
module "name_specific_subnet" {
@@ -48,6 +37,16 @@ module "name_specific_subnet" {
4837

4938
#subnet
5039
specific_name_subnet = true
51-
specific_subnet_names = "GatewaySubnet"
40+
specific_subnet_names = "SpecificSubnet"
5241
subnet_prefixes = ["10.0.1.0/24"]
42+
43+
# route_table
44+
enable_route_table = false
45+
routes = [
46+
{
47+
name = "rt-test"
48+
address_prefix = "0.0.0.0/0"
49+
next_hop_type = "Internet"
50+
}
51+
]
5352
}

_example/name_specific_subnet/output.tf renamed to _example/name-specific_subnet/output.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,14 @@ output "address_prefixes" {
2222
description = "The address prefixes for the subnet."
2323
value = module.name_specific_subnet.specific_subnet_address_prefixes
2424
}
25+
26+
output "route_table_id" {
27+
description = "The Route Table ID."
28+
value = module.name_specific_subnet.route_table_id
29+
}
30+
31+
output "route_table_associated_subnets" {
32+
description = "The collection of Subnets associated with this route table."
33+
value = module.name_specific_subnet.*.route_table_associated_subnets[0]
34+
}
35+

_example/nat-gateway-subnet/example.tf renamed to _example/nat-gateway_subnet/example.tf

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ module "resource_group" {
66
source = "clouddrove/resource-group/azure"
77
version = "1.0.0"
88

9-
name = "app-13"
9+
name = "app"
1010
environment = "test"
1111
label_order = ["environment", "name", ]
1212
location = "North Europe"
1313
}
1414

1515
module "vnet" {
16-
source = "clouddrove/virtual-network/azure"
17-
version = "1.0.3"
16+
source = "clouddrove/vnet/azure"
17+
version = "1.0.0"
1818

1919
name = "app"
2020
environment = "test"
@@ -23,17 +23,6 @@ module "vnet" {
2323
location = module.resource_group.resource_group_location
2424
address_space = "10.0.0.0/16"
2525
enable_ddos_pp = false
26-
27-
28-
# routes
29-
enabled_route_table = false
30-
routes = [
31-
{
32-
name = "rt-test"
33-
address_prefix = "0.0.0.0/0"
34-
next_hop_type = "Internet"
35-
}
36-
]
3726
}
3827

3928
module "subnet" {
@@ -51,4 +40,14 @@ module "subnet" {
5140
create_nat_gateway = true
5241
subnet_names = ["subnet1", "subnet2"]
5342
subnet_prefixes = ["10.0.1.0/24", "10.0.2.0/24"]
43+
44+
# route_table
45+
enable_route_table = false
46+
routes = [
47+
{
48+
name = "rt-test"
49+
address_prefix = "0.0.0.0/0"
50+
next_hop_type = "Internet"
51+
}
52+
]
5453
}

_example/nat-gateway-subnet/output.tf renamed to _example/nat-gateway_subnet/output.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,13 @@ output "public_ip_id" {
3737
description = " The ID of this Public IP."
3838
value = module.subnet.public_ip_id
3939
}
40+
41+
output "route_table_id" {
42+
description = "The Route Table ID."
43+
value = module.subnet.route_table_id
44+
}
45+
46+
output "route_table_associated_subnets" {
47+
description = "The collection of Subnets associated with this route table."
48+
value = module.subnet.*.route_table_associated_subnets[0]
49+
}

main.tf

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,34 @@ resource "azurerm_subnet_nat_gateway_association" "subnet_assoc" {
9595
nat_gateway_id = join("", azurerm_nat_gateway.natgw.*.id)
9696
subnet_id = var.default_name_subnet == true ? azurerm_subnet.subnet.*.id[count.index] : azurerm_subnet.subnet2.*.id[count.index]
9797
}
98+
99+
#Route Table
100+
resource "azurerm_route_table" "rt" {
101+
count = var.enable && var.enable_route_table ? 1 : 0
102+
name = format("%s-route-table", module.labels.id)
103+
location = var.location
104+
resource_group_name = var.resource_group_name
105+
dynamic "route" {
106+
for_each = var.routes
107+
content {
108+
name = route.value.name
109+
address_prefix = route.value.address_prefix
110+
next_hop_type = route.value.next_hop_type
111+
next_hop_in_ip_address = lookup(route.value, "next_hop_in_ip_address", null)
112+
}
113+
}
114+
disable_bgp_route_propagation = var.disable_bgp_route_propagation
115+
tags = module.labels.tags
116+
}
117+
118+
resource "azurerm_subnet_route_table_association" "main" {
119+
count = var.enable && var.enable_route_table && var.default_name_subnet ? length(var.subnet_prefixes) : 0
120+
subnet_id = element(azurerm_subnet.subnet.*.id, count.index)
121+
route_table_id = join("", azurerm_route_table.rt.*.id)
122+
}
123+
124+
resource "azurerm_subnet_route_table_association" "main2" {
125+
count = var.enable && var.enable_route_table && var.specific_name_subnet ? length(var.subnet_prefixes) : 0
126+
subnet_id = element(azurerm_subnet.subnet2.*.id, count.index)
127+
route_table_id = join("", azurerm_route_table.rt.*.id)
128+
}

output.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,14 @@ output "public_ip_id" {
4242
description = " The ID of this Public IP."
4343
value = azurerm_public_ip.pip.*.id
4444
}
45+
46+
47+
output "route_table_id" {
48+
description = "The Route Table ID."
49+
value = var.enable_route_table ? azurerm_route_table.rt.*.id : null
50+
}
51+
52+
output "route_table_associated_subnets" {
53+
description = "The collection of Subnets associated with this route table."
54+
value = var.enable_route_table ? azurerm_route_table.rt.*.subnets[0] : null
55+
}

variable.tf

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,26 @@ variable "nat_gateway_idle_timeout" {
142142
}
143143

144144
variable "create_nat_gateway" {
145-
type = bool
146-
default = false
145+
type = bool
146+
default = false
147+
description = "Flag to control nat gateway creation."
148+
}
149+
150+
variable "enable_route_table" {
151+
type = bool
152+
default = false
153+
description = "Flag to control route table creation."
154+
}
155+
156+
variable "routes" {
157+
type = list(map(string))
158+
default = []
159+
description = "List of objects that represent the configuration of each route."
160+
/*ROUTES = [{ name = "", address_prefix = "", next_hop_type = "", next_hop_in_ip_address = "" }]*/
161+
}
162+
163+
variable "disable_bgp_route_propagation" {
164+
type = bool
165+
default = true
166+
description = "Boolean flag which controls propagation of routes learned by BGP on that route table."
147167
}

0 commit comments

Comments
 (0)