Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

Commit

Permalink
Add route tables to subnets (#7)
Browse files Browse the repository at this point in the history
* Reset to master upstream and add route tables associations

* Fix fmt

* Add example
  • Loading branch information
jmapro authored Jul 27, 2020
1 parent 83cb4f7 commit b093046
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,53 @@ resource "azurerm_network_security_group" "ssh" {
}
```

## Example adding a route table

```hcl
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "example" {
name = "my-resources"
location = "West Europe"
}
module "vnet" {
source = "Azure/vnet/azurerm"
resource_group_name = azurerm_resource_group.example.name
address_space = ["10.0.0.0/16"]
subnet_prefixes = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]
subnet_names = ["subnet1", "subnet2", "subnet3"]
route_table_ids = {
subnet1 = azurerm_route_table.example.id
subnet2 = azurerm_route_table.example.id
subnet3 = azurerm_roiute_table.example.id
}
tags = {
environment = "dev"
costcenter = "it"
}
}
resource "azurerm_route_table" "example" {
location = azurerm_resource_group.example.location
name = "MyRouteTable"
resource_group_name = azurerm_resource_group.example.name
}
resource "azurerm_route" "example" {
name = "acceptanceTestRoute1"
resource_group_name = azurerm_resource_group.example.name
route_table_name = azurerm_route_table.example.name
address_prefix = "10.1.0.0/16"
next_hop_type = "vnetlocal"
}
```
## Test

### Configurations
Expand Down
6 changes: 6 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,10 @@ resource "azurerm_subnet_network_security_group_association" "vnet" {
for_each = var.nsg_ids
subnet_id = data.azurerm_subnet.import[each.key].id
network_security_group_id = each.value
}

resource "azurerm_subnet_route_table_association" "vnet" {
for_each = var.route_tables_ids
route_table_id = each.value
subnet_id = data.azurerm_subnet.import[each.key].id
}
10 changes: 10 additions & 0 deletions test/fixture/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ resource "azurerm_network_security_group" "nsg1" {
location = azurerm_resource_group.test.location
}

resource "azurerm_route_table" "rt1" {
location = azurerm_resource_group.test.location
name = "test-${random_id.rg_name.hex}-rt"
resource_group_name = azurerm_resource_group.test.name
}

module "vnet" {
source = "../../"
resource_group_name = azurerm_resource_group.test.name
Expand All @@ -28,6 +34,10 @@ module "vnet" {
subnet1 = azurerm_network_security_group.nsg1.id
}

route_tables_ids = {
subnet1 = azurerm_route_table.rt1.id
}

tags = {
environment = "dev"
costcenter = "it"
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ variable "nsg_ids" {
}
}

variable "route_tables_ids" {
description = "A map of subnet name to Route table ids"
type = map(string)
default = {}
}

variable "tags" {
description = "The tags to associate with your network and subnets."
type = map(string)
Expand Down

0 comments on commit b093046

Please sign in to comment.