Skip to content

Commit

Permalink
Merge pull request #3 from clouddrove/internal-274-a
Browse files Browse the repository at this point in the history
Route Table Addition
  • Loading branch information
d4kverma committed Dec 28, 2022
2 parents 4cd0276 + b3434b7 commit d3981ac
Show file tree
Hide file tree
Showing 10 changed files with 165 additions and 45 deletions.
34 changes: 32 additions & 2 deletions README.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ usage: |-
default_name_subnet = true
subnet_names = ["subnet1", "subnet2"]
subnet_prefixes = ["10.0.1.0/24", "10.0.2.0/24"]
# route_table
enable_route_table = false
routes = [
{
name = "rt-test"
address_prefix = "0.0.0.0/0"
next_hop_type = "Internet"
}
]
}
```
### Name_Specific Subnet
Expand All @@ -67,11 +77,21 @@ usage: |-
#subnet
specific_name_subnet = true
specific_subnet_names = "GatewaySubnet"
specific_subnet_names = "SpecificSubnet"
subnet_prefixes = ["10.0.1.0/24"]
# route_table
enable_route_table = false
routes = [
{
name = "rt-test"
address_prefix = "0.0.0.0/0"
next_hop_type = "Internet"
}
]
}
```
### Nat_Gateway_Subnet
### Nat_Gateway Subnet
```hcl
module "name_specific_subnet" {
source = "clouddrove/subnet/azure"
Expand All @@ -87,5 +107,15 @@ usage: |-
create_nat_gateway = true
subnet_names = ["subnet1", "subnet2"]
subnet_prefixes = ["10.0.1.0/24", "10.0.2.0/24"]
# route_table
enable_route_table = false
routes = [
{
name = "rt-test"
address_prefix = "0.0.0.0/0"
next_hop_type = "Internet"
}
]
}
```
25 changes: 12 additions & 13 deletions _example/default_subnet/example.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ module "resource_group" {
}

module "vnet" {
source = "clouddrove/virtual-network/azure"
version = "1.0.3"
source = "clouddrove/vnet/azure"
version = "1.0.0"

name = "app"
environment = "test"
Expand All @@ -23,17 +23,6 @@ module "vnet" {
location = module.resource_group.resource_group_location
address_space = "10.0.0.0/16"
enable_ddos_pp = false


# routes
enabled_route_table = false
routes = [
{
name = "rt-test"
address_prefix = "0.0.0.0/0"
next_hop_type = "Internet"
}
]
}

module "subnet" {
Expand All @@ -50,4 +39,14 @@ module "subnet" {
default_name_subnet = true
subnet_names = ["subnet1", "subnet2"]
subnet_prefixes = ["10.0.1.0/24", "10.0.2.0/24"]

# route_table
enable_route_table = false
routes = [
{
name = "rt-test"
address_prefix = "0.0.0.0/0"
next_hop_type = "Internet"
}
]
}
10 changes: 10 additions & 0 deletions _example/default_subnet/output.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,14 @@ output "virtual_network_name" {
output "address_prefixes" {
description = "The address prefixes for the subnet."
value = module.subnet.default_subnet_address_prefixes
}

output "route_table_id" {
description = "The Route Table ID."
value = module.subnet.route_table_id
}

output "route_table_associated_subnets" {
description = "The collection of Subnets associated with this route table."
value = module.subnet.*.route_table_associated_subnets[0]
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ module "resource_group" {
}

module "vnet" {
source = "clouddrove/virtual-network/azure"
version = "1.0.3"
source = "clouddrove/vnet/azure"
version = "1.0.0"

name = "app"
environment = "test"
Expand All @@ -23,17 +23,6 @@ module "vnet" {
location = module.resource_group.resource_group_location
address_space = "10.0.0.0/16"
enable_ddos_pp = false


# routes
enabled_route_table = false
routes = [
{
name = "rt-test"
address_prefix = "0.0.0.0/0"
next_hop_type = "Internet"
}
]
}

module "name_specific_subnet" {
Expand All @@ -48,6 +37,16 @@ module "name_specific_subnet" {

#subnet
specific_name_subnet = true
specific_subnet_names = "GatewaySubnet"
specific_subnet_names = "SpecificSubnet"
subnet_prefixes = ["10.0.1.0/24"]

# route_table
enable_route_table = false
routes = [
{
name = "rt-test"
address_prefix = "0.0.0.0/0"
next_hop_type = "Internet"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,14 @@ output "address_prefixes" {
description = "The address prefixes for the subnet."
value = module.name_specific_subnet.specific_subnet_address_prefixes
}

output "route_table_id" {
description = "The Route Table ID."
value = module.name_specific_subnet.route_table_id
}

output "route_table_associated_subnets" {
description = "The collection of Subnets associated with this route table."
value = module.name_specific_subnet.*.route_table_associated_subnets[0]
}

Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ module "resource_group" {
source = "clouddrove/resource-group/azure"
version = "1.0.0"

name = "app-13"
name = "app"
environment = "test"
label_order = ["environment", "name", ]
location = "North Europe"
}

module "vnet" {
source = "clouddrove/virtual-network/azure"
version = "1.0.3"
source = "clouddrove/vnet/azure"
version = "1.0.0"

name = "app"
environment = "test"
Expand All @@ -23,17 +23,6 @@ module "vnet" {
location = module.resource_group.resource_group_location
address_space = "10.0.0.0/16"
enable_ddos_pp = false


# routes
enabled_route_table = false
routes = [
{
name = "rt-test"
address_prefix = "0.0.0.0/0"
next_hop_type = "Internet"
}
]
}

module "subnet" {
Expand All @@ -51,4 +40,14 @@ module "subnet" {
create_nat_gateway = true
subnet_names = ["subnet1", "subnet2"]
subnet_prefixes = ["10.0.1.0/24", "10.0.2.0/24"]

# route_table
enable_route_table = false
routes = [
{
name = "rt-test"
address_prefix = "0.0.0.0/0"
next_hop_type = "Internet"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,13 @@ output "public_ip_id" {
description = " The ID of this Public IP."
value = module.subnet.public_ip_id
}

output "route_table_id" {
description = "The Route Table ID."
value = module.subnet.route_table_id
}

output "route_table_associated_subnets" {
description = "The collection of Subnets associated with this route table."
value = module.subnet.*.route_table_associated_subnets[0]
}
31 changes: 31 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,34 @@ resource "azurerm_subnet_nat_gateway_association" "subnet_assoc" {
nat_gateway_id = join("", azurerm_nat_gateway.natgw.*.id)
subnet_id = var.default_name_subnet == true ? azurerm_subnet.subnet.*.id[count.index] : azurerm_subnet.subnet2.*.id[count.index]
}

#Route Table
resource "azurerm_route_table" "rt" {
count = var.enable && var.enable_route_table ? 1 : 0
name = format("%s-route-table", module.labels.id)
location = var.location
resource_group_name = var.resource_group_name
dynamic "route" {
for_each = var.routes
content {
name = route.value.name
address_prefix = route.value.address_prefix
next_hop_type = route.value.next_hop_type
next_hop_in_ip_address = lookup(route.value, "next_hop_in_ip_address", null)
}
}
disable_bgp_route_propagation = var.disable_bgp_route_propagation
tags = module.labels.tags
}

resource "azurerm_subnet_route_table_association" "main" {
count = var.enable && var.enable_route_table && var.default_name_subnet ? length(var.subnet_prefixes) : 0
subnet_id = element(azurerm_subnet.subnet.*.id, count.index)
route_table_id = join("", azurerm_route_table.rt.*.id)
}

resource "azurerm_subnet_route_table_association" "main2" {
count = var.enable && var.enable_route_table && var.specific_name_subnet ? length(var.subnet_prefixes) : 0
subnet_id = element(azurerm_subnet.subnet2.*.id, count.index)
route_table_id = join("", azurerm_route_table.rt.*.id)
}
11 changes: 11 additions & 0 deletions output.tf
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,14 @@ output "public_ip_id" {
description = " The ID of this Public IP."
value = azurerm_public_ip.pip.*.id
}


output "route_table_id" {
description = "The Route Table ID."
value = var.enable_route_table ? azurerm_route_table.rt.*.id : null
}

output "route_table_associated_subnets" {
description = "The collection of Subnets associated with this route table."
value = var.enable_route_table ? azurerm_route_table.rt.*.subnets[0] : null
}
24 changes: 22 additions & 2 deletions variable.tf
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,26 @@ variable "nat_gateway_idle_timeout" {
}

variable "create_nat_gateway" {
type = bool
default = false
type = bool
default = false
description = "Flag to control nat gateway creation."
}

variable "enable_route_table" {
type = bool
default = false
description = "Flag to control route table creation."
}

variable "routes" {
type = list(map(string))
default = []
description = "List of objects that represent the configuration of each route."
/*ROUTES = [{ name = "", address_prefix = "", next_hop_type = "", next_hop_in_ip_address = "" }]*/
}

variable "disable_bgp_route_propagation" {
type = bool
default = true
description = "Boolean flag which controls propagation of routes learned by BGP on that route table."
}

0 comments on commit d3981ac

Please sign in to comment.