Skip to content

Commit

Permalink
refactor: Improve organization of Azure Route Table module
Browse files Browse the repository at this point in the history
  • Loading branch information
spy86 committed Mar 6, 2024
1 parent e081940 commit f1f27ad
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 80 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 Maciej Michalski
Copyright (c) 2024 ThinkCube

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
36 changes: 17 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.15 |
| <a name="requirement_azurerm"></a> [azurerm](#requirement\_azurerm) | 3.3.0 |
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.6.4 |
| <a name="requirement_azurerm"></a> [azurerm](#requirement\_azurerm) | 3.94.0 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_azurerm"></a> [azurerm](#provider\_azurerm) | 3.3.0 |
| <a name="provider_azurerm"></a> [azurerm](#provider\_azurerm) | 3.94.0 |

## Modules

Expand All @@ -20,32 +20,30 @@ No modules.

| Name | Type |
|------|------|
| [azurerm_route_table.routetable](https://registry.terraform.io/providers/hashicorp/azurerm/3.3.0/docs/resources/route_table) | resource |
| [azurerm_client_config.current](https://registry.terraform.io/providers/hashicorp/azurerm/3.3.0/docs/data-sources/client_config) | data source |
| [azurerm_resource_group.rg](https://registry.terraform.io/providers/hashicorp/azurerm/3.3.0/docs/data-sources/resource_group) | data source |
| [azurerm_route_table.main](https://registry.terraform.io/providers/hashicorp/azurerm/3.94.0/docs/resources/route_table) | resource |
| [azurerm_client_config.current](https://registry.terraform.io/providers/hashicorp/azurerm/3.94.0/docs/data-sources/client_config) | data source |
| [azurerm_resource_group.main](https://registry.terraform.io/providers/hashicorp/azurerm/3.94.0/docs/data-sources/resource_group) | data source |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_default_tags"></a> [default\_tags](#input\_default\_tags) | A mapping of tags to assign to the resource. | `map` | n/a | yes |
| <a name="input_environment"></a> [environment](#input\_environment) | Var used for backend container name key | `string` | `"dev"` | no |
| <a name="input_name"></a> [name](#input\_name) | The name of the route table. Changing this forces a new resource to be created. | `string` | n/a | yes |
| <a name="input_region"></a> [region](#input\_region) | Region in which resources are deployed | `string` | `"weu"` | no |
| <a name="input_resource_group_location"></a> [resource\_group\_location](#input\_resource\_group\_location) | The location/region where the virtual network is created. Changing this forces a new resource to be created. | `string` | `"West Europe"` | no |
| <a name="input_resource_group_name"></a> [resource\_group\_name](#input\_resource\_group\_name) | The name of the resource group in which to create the virtual network. | `string` | n/a | yes |
| <a name="input_default_tags"></a> [default\_tags](#input\_default\_tags) | A mapping of tags to assign to the resource. | `map(any)` | <pre>{<br> "ManagedByTerraform": "True"<br>}</pre> | no |
| <a name="input_environment"></a> [environment](#input\_environment) | Variable that defines the name of the environment. | `string` | `"dev"` | no |
| <a name="input_region"></a> [region](#input\_region) | Region in which resources are deployed. | `string` | `"weu"` | no |
| <a name="input_resource_group_location"></a> [resource\_group\_location](#input\_resource\_group\_location) | Specifies the supported Azure location where the resource exists. Changing this forces a new resource to be created. | `any` | n/a | yes |
| <a name="input_resource_group_name"></a> [resource\_group\_name](#input\_resource\_group\_name) | The name of the resource group in which to create the route table. Changing this forces a new resource to be created. | `any` | n/a | yes |
| <a name="input_route_table"></a> [route\_table](#input\_route\_table) | List of objects representing routes. Each object accepts the arguments documented below. | `list(map(string))` | `[]` | no |
| <a name="input_route_table_disable_bgp_route_propagation"></a> [route\_table\_disable\_bgp\_route\_propagation](#input\_route\_table\_disable\_bgp\_route\_propagation) | Boolean flag which controls propagation of routes learned by BGP on that route table. True means disable. | `bool` | `true` | no |
| <a name="input_route_table_name"></a> [route\_table\_name](#input\_route\_table\_name) | The name of the route table. Changing this forces a new resource to be created. | `string` | n/a | yes |

## Outputs

| Name | Description |
|------|-------------|
| <a name="output_id"></a> [id](#output\_id) | The Route Table ID. |
| <a name="output_location"></a> [location](#output\_location) | Azure location where where the route table is created. |
| <a name="output_name"></a> [name](#output\_name) | The name of the route table. |
| <a name="output_resource_group_name"></a> [resource\_group\_name](#output\_resource\_group\_name) | The name of the resource group in which to create the route table. |
| <a name="output_routes"></a> [routes](#output\_routes) | List of objects representing routes. |
| <a name="output_subnets"></a> [subnets](#output\_subnets) | The collection of Subnets associated with this route table. |
| <a name="output_tags"></a> [tags](#output\_tags) | A mapping of tags to assign to the resource. |
| <a name="output_location"></a> [location](#output\_location) | Azure location where the resource exists. |
| <a name="output_resource_group_name"></a> [resource\_group\_name](#output\_resource\_group\_name) | The name of the resource group in which to create the route table |
| <a name="output_route_entries"></a> [route\_entries](#output\_route\_entries) | Objects representing routes |
| <a name="output_route_table_id"></a> [route\_table\_id](#output\_route\_table\_id) | The Route Table ID. |
| <a name="output_route_table_name"></a> [route\_table\_name](#output\_route\_table\_name) | The name of the route table. |
<!-- END_TF_DOCS -->
6 changes: 3 additions & 3 deletions backend.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "3.3.0"
source = "hashicorp/azurerm"
version = "3.94.0"
}
}
required_version = ">= 0.15"
required_version = ">= 1.6.4"
}
66 changes: 56 additions & 10 deletions examples/route-table/README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,70 @@
# Terraform Module for Azure Route Table
# Terraform Module: Azure Route Table

Terraform module for management Azure Route Tables wchich allow you to create network routes.
This Terraform module creates an Azure Route Table with dynamic route entries.

# How to use
```
module "route-table" {
source = "spy86/route-table/azure"
version = "1.0.3"
name = "dev-routetable"
## Features

- **Dynamic Route Entries:** Define dynamic route entries as a list of objects, each representing a route with a name, address prefix, next hop type, and optional next hop IP address.

- **Tagging:** Automatically tags the created resources with common tags for better organization and management.

- **BGP Route Propagation:** Option to disable propagation of routes learned by BGP on the route table.

## Usage

### Example

```hcl
provider "azurerm" {
features {}
}
module "route_table" {
source = "Think-Cube/route-table/azure"
version = "1.0.0"
route_table_name = "routetable"
resource_group_name = "weu-test-rg"
resource_group_location = "West Europe"
environment = "dev"
region = "weu"
routes = [
route_table = [
{ name = "Route-01", address_prefix = "10.10.0.0/16", next_hop_type = "VirtualAppliance", next_hop_in_ip_address = "10.0.0.12" },
{ name = "Route-02", address_prefix = "10.20.0.0/16", next_hop_type = "VirtualAppliance", next_hop_in_ip_address = "10.0.0.16" },
{ name = "Route-03", address_prefix = "0.0.0.0/0", next_hop_type = "Internet" }
]
route_table_disable_bgp_route_propagation = "true"
default_tags = {
Administrator = "John Doe"
Department = "IT"
CostCentre = "CC123"
ContactPerson = "Jane Smith"
ManagedByTerraform = "True"
}
}
```

More info You can find in [README.md](https://github.com/spy86/terraform-azure-route-table/blob/main/README.md)
### Variables

- `environment`: Variable that defines the name of the environment.
- `default_tags`: A mapping of tags to assign to the resource.
- `region`: Region in which resources are deployed.
- `resource_group_location`: Specifies the supported Azure location where the resource exists.
- `resource_group_name`: The name of the resource group in which to create the route table.
- `route_table`: The name of the route table.
- `route_table_disable_bgp_route_propagation`: Boolean flag to control propagation of routes learned by BGP on that route table.

### Outputs

- `route_table_id`: The Route Table ID.
- `route_table_name`: The name of the route table.
- `route_entries`: Objects representing routes.
- `location`: Azure location where the resource exists.
- `resource_group_name`: The name of the resource group in which the route table was created.

## License

This project is licensed under the [MIT License](https://opensource.org/licenses/MIT).

## Contribution

Feel free to contribute by opening issues or pull requests. Your feedback and improvements are highly appreciated!
4 changes: 2 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
data "azurerm_client_config" "current" {}

data "azurerm_resource_group" "rg" {
name = "${var.resource_group_name}"
data "azurerm_resource_group" "main" {
name = var.resource_group_name
}
39 changes: 17 additions & 22 deletions output.tf
Original file line number Diff line number Diff line change
@@ -1,34 +1,29 @@
output "id" {
value = "${azurerm_route_table.routetable.id}"
output "route_table_id" {
description = "The Route Table ID."
value = azurerm_route_table.main.id
sensitive = false
}

output "name" {
value = "${azurerm_route_table.routetable.name}"
output "route_table_name" {
description = "The name of the route table."
value = azurerm_route_table.main.name
sensitive = false
}

output "resource_group_name" {
value = "${azurerm_route_table.routetable.resource_group_name}"
description = "The name of the resource group in which to create the route table."
output "route_entries" {
description = "Objects representing routes"
value = azurerm_route_table.main.route[*].name
sensitive = false
}

output "location" {
value = "${azurerm_route_table.routetable.location}"
description = "Azure location where where the route table is created."
}

output "routes" {
value = "${azurerm_route_table.routetable.route}"
description = "List of objects representing routes."
description = "Azure location where the resource exists."
value = azurerm_route_table.main.location
sensitive = false
}

output "subnets" {
value = "${azurerm_route_table.routetable.subnets}"
description = "The collection of Subnets associated with this route table."
output "resource_group_name" {
description = "The name of the resource group in which to create the route table"
value = azurerm_route_table.main.resource_group_name
sensitive = false
}

output "tags" {
value = "${azurerm_route_table.routetable.tags}"
description = "A mapping of tags to assign to the resource."
}
12 changes: 6 additions & 6 deletions route_table.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
resource "azurerm_route_table" "routetable" {
name = "${var.environment}-${var.name}-${var.region}-rt"
location = "${data.azurerm_resource_group.rg.location}"
resource_group_name = "${data.azurerm_resource_group.rg.name}"
resource "azurerm_route_table" "main" {
name = "${var.environment}-${var.route_table_name}-${var.region}-rt"
location = data.azurerm_resource_group.rg.location
resource_group_name = data.azurerm_resource_group.rg.name
dynamic "route" {
for_each = var.route_table
content {
Expand All @@ -11,6 +11,6 @@ resource "azurerm_route_table" "routetable" {
next_hop_in_ip_address = lookup(route.value, "next_hop_in_ip_address", null)
}
}
disable_bgp_route_propagation = "${var.route_table_disable_bgp_route_propagation}"
tags = "${var.default_tags}"
disable_bgp_route_propagation = var.route_table_disable_bgp_route_propagation
tags = var.default_tags
}
34 changes: 17 additions & 17 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,35 @@
# Common vars
###########################
variable "environment" {
description = "Var used for backend container name key"
type = string
default = "dev"
description = "Variable that defines the name of the environment."
type = string
default = "dev"
}
variable "default_tags" {
description = "A mapping of tags to assign to the resource."
type = map
type = map(any)
default = {
"ManagedByTerraform" = "True"
}
}
variable "region" {
description = "Region in which resources are deployed"
type = string
default = "weu"
description = "Region in which resources are deployed."
type = string
default = "weu"
}
###########################
# Resource groups vars
###########################
############################
#Resource gropus vars
############################
variable "resource_group_location" {
description = "The location/region where the virtual network is created. Changing this forces a new resource to be created."
default = "West Europe"
type = string
description = "Specifies the supported Azure location where the resource exists. Changing this forces a new resource to be created."
}
variable "resource_group_name" {
description = "The name of the resource group in which to create the virtual network."
type = string
description = "The name of the resource group in which to create the route table. Changing this forces a new resource to be created."
}
############################
#ROUTE TABLE variable
#Route table variable
############################
variable "name" {
variable "route_table_name" {
type = string
description = "The name of the route table. Changing this forces a new resource to be created."
}
Expand Down

0 comments on commit f1f27ad

Please sign in to comment.