From bd0326138bb51c3c2b2fffbcb7694f486521e92b Mon Sep 17 00:00:00 2001 From: KoomeKiriinya Date: Tue, 16 Jul 2024 18:22:46 +0300 Subject: [PATCH 1/4] updating vnet module to pass az as variable, rename nat gateways with environments --- modules/azure/networking/main.tf | 6 +++--- modules/azure/networking/variables.tf | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/modules/azure/networking/main.tf b/modules/azure/networking/main.tf index a0e882c..657c368 100644 --- a/modules/azure/networking/main.tf +++ b/modules/azure/networking/main.tf @@ -27,12 +27,12 @@ resource "azurerm_subnet" "subnets" { resource "azurerm_public_ip" "nat_address" { count = 2 - name = "nat-external-address-${count.index}" + name = "${var.environment}-nat-external-address-${count.index}" location = var.vnet_location resource_group_name = var.resource_group_name allocation_method = "Static" sku = "Standard" - zones = ["1"] + zones = var.availability_zones } resource "azurerm_nat_gateway" "nat_gateway" { @@ -41,7 +41,7 @@ resource "azurerm_nat_gateway" "nat_gateway" { resource_group_name = var.resource_group_name sku_name = "Standard" idle_timeout_in_minutes = 10 - zones = ["1"] + zones = var.availability_zones } resource "azurerm_nat_gateway_public_ip_association" "nat_address_gateway_association" { diff --git a/modules/azure/networking/variables.tf b/modules/azure/networking/variables.tf index 00f4bd0..c10e0b6 100644 --- a/modules/azure/networking/variables.tf +++ b/modules/azure/networking/variables.tf @@ -18,6 +18,11 @@ variable "vnet_location" { type = string } +variable "availability_zones" { + description = "Availability zones for nat gateway and public ips" + type = list(string) +} + variable "vnet_address_space" { description = "Address space for the virtual network" type = list(string) From 038fe4262eb149ebf111c4a65b078b0b9cbdcd09 Mon Sep 17 00:00:00 2001 From: KoomeKiriinya Date: Thu, 18 Jul 2024 22:35:06 +0300 Subject: [PATCH 2/4] pre-commit fix --- modules/azure/networking/README.md | 1 + modules/azure/networking/variables.tf | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/azure/networking/README.md b/modules/azure/networking/README.md index 6f511e9..29a4147 100644 --- a/modules/azure/networking/README.md +++ b/modules/azure/networking/README.md @@ -89,6 +89,7 @@ No modules. | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| +| [availability\_zones](#input\_availability\_zones) | Availability zones for nat gateway and public ips | `list(string)` | n/a | yes | | [environment](#input\_environment) | Environment like: infra-ops, dev, stage, prod | `string` | n/a | yes | | [resource\_group\_name](#input\_resource\_group\_name) | Azure resource group name | `string` | n/a | yes | | [subnets](#input\_subnets) | Azure subnets and their configuration |
map(object({
address_prefixes = list(string)
enable_nat = bool
service_endpoints = list(string)
private_endpoint_network_policies = string # Allowed values: "Disabled", "Enabled", "NetworkSecurityGroupEnabled" and "RouteTableEnabled"
delegations = map(object({
service_delegation_name = string
service_delegation_actions = list(string)
}))
security_rules = optional(map(object({
priority = number
direction = string
access = string
protocol = string
source_port_range = optional(string)
source_port_ranges = optional(list(string))
destination_port_range = optional(string)
destination_port_ranges = optional(list(string))
source_address_prefix = optional(string)
source_address_prefixes = optional(list(string))
destination_address_prefix = optional(string)
destination_address_prefixes = optional(list(string))
source_application_security_group_ids = optional(list(string))
})), {})
routes = optional(map(object({
address_prefix = string
next_hop_type = string
next_hop_in_ip_address = optional(string)
})))
}))
| n/a | yes | diff --git a/modules/azure/networking/variables.tf b/modules/azure/networking/variables.tf index c10e0b6..11d4372 100644 --- a/modules/azure/networking/variables.tf +++ b/modules/azure/networking/variables.tf @@ -20,7 +20,7 @@ variable "vnet_location" { variable "availability_zones" { description = "Availability zones for nat gateway and public ips" - type = list(string) + type = list(string) } variable "vnet_address_space" { From 949a031d1dcd6424ad752a0e379b9c6c4d00a974 Mon Sep 17 00:00:00 2001 From: KoomeKiriinya Date: Thu, 18 Jul 2024 22:54:51 +0300 Subject: [PATCH 3/4] add optional prefix for nat --- modules/azure/networking/README.md | 2 +- modules/azure/networking/main.tf | 4 ++-- modules/azure/networking/variables.tf | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/azure/networking/README.md b/modules/azure/networking/README.md index 29a4147..4cbf9a9 100644 --- a/modules/azure/networking/README.md +++ b/modules/azure/networking/README.md @@ -90,7 +90,7 @@ No modules. | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| | [availability\_zones](#input\_availability\_zones) | Availability zones for nat gateway and public ips | `list(string)` | n/a | yes | -| [environment](#input\_environment) | Environment like: infra-ops, dev, stage, prod | `string` | n/a | yes | +| [nat\_prefix](#input\_nat\_prefix) | Prefix of the nat gateway & public ip address | `string` | n/a | yes | | [resource\_group\_name](#input\_resource\_group\_name) | Azure resource group name | `string` | n/a | yes | | [subnets](#input\_subnets) | Azure subnets and their configuration |
map(object({
address_prefixes = list(string)
enable_nat = bool
service_endpoints = list(string)
private_endpoint_network_policies = string # Allowed values: "Disabled", "Enabled", "NetworkSecurityGroupEnabled" and "RouteTableEnabled"
delegations = map(object({
service_delegation_name = string
service_delegation_actions = list(string)
}))
security_rules = optional(map(object({
priority = number
direction = string
access = string
protocol = string
source_port_range = optional(string)
source_port_ranges = optional(list(string))
destination_port_range = optional(string)
destination_port_ranges = optional(list(string))
source_address_prefix = optional(string)
source_address_prefixes = optional(list(string))
destination_address_prefix = optional(string)
destination_address_prefixes = optional(list(string))
source_application_security_group_ids = optional(list(string))
})), {})
routes = optional(map(object({
address_prefix = string
next_hop_type = string
next_hop_in_ip_address = optional(string)
})))
}))
| n/a | yes | | [vnet\_address\_space](#input\_vnet\_address\_space) | Address space for the virtual network | `list(string)` | n/a | yes | diff --git a/modules/azure/networking/main.tf b/modules/azure/networking/main.tf index 657c368..2786115 100644 --- a/modules/azure/networking/main.tf +++ b/modules/azure/networking/main.tf @@ -27,7 +27,7 @@ resource "azurerm_subnet" "subnets" { resource "azurerm_public_ip" "nat_address" { count = 2 - name = "${var.environment}-nat-external-address-${count.index}" + name = "${var.nat_prefix}-nat-external-address-${count.index}" location = var.vnet_location resource_group_name = var.resource_group_name allocation_method = "Static" @@ -36,7 +36,7 @@ resource "azurerm_public_ip" "nat_address" { } resource "azurerm_nat_gateway" "nat_gateway" { - name = "${var.environment}-nat-gateway" + name = "${var.nat_prefix}-nat-gateway" location = var.vnet_location resource_group_name = var.resource_group_name sku_name = "Standard" diff --git a/modules/azure/networking/variables.tf b/modules/azure/networking/variables.tf index 11d4372..85ff3c3 100644 --- a/modules/azure/networking/variables.tf +++ b/modules/azure/networking/variables.tf @@ -1,8 +1,3 @@ -variable "environment" { - description = "Environment like: infra-ops, dev, stage, prod" - type = string -} - variable "resource_group_name" { description = "Azure resource group name" type = string @@ -28,6 +23,11 @@ variable "vnet_address_space" { type = list(string) } +variable "nat_prefix" { + description = "Prefix of the nat gateway & public ip address" + type = string + +} variable "subnets" { description = "Azure subnets and their configuration" type = map(object({ From fb5fa930f90bcf532eff6975f4874c6cef165f13 Mon Sep 17 00:00:00 2001 From: KoomeKiriinya Date: Thu, 18 Jul 2024 22:59:31 +0300 Subject: [PATCH 4/4] nat_prefix default as empty string --- modules/azure/networking/README.md | 2 +- modules/azure/networking/variables.tf | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/azure/networking/README.md b/modules/azure/networking/README.md index 4cbf9a9..5cbd306 100644 --- a/modules/azure/networking/README.md +++ b/modules/azure/networking/README.md @@ -90,7 +90,7 @@ No modules. | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| | [availability\_zones](#input\_availability\_zones) | Availability zones for nat gateway and public ips | `list(string)` | n/a | yes | -| [nat\_prefix](#input\_nat\_prefix) | Prefix of the nat gateway & public ip address | `string` | n/a | yes | +| [nat\_prefix](#input\_nat\_prefix) | Prefix of the nat gateway & public ip address | `string` | `""` | no | | [resource\_group\_name](#input\_resource\_group\_name) | Azure resource group name | `string` | n/a | yes | | [subnets](#input\_subnets) | Azure subnets and their configuration |
map(object({
address_prefixes = list(string)
enable_nat = bool
service_endpoints = list(string)
private_endpoint_network_policies = string # Allowed values: "Disabled", "Enabled", "NetworkSecurityGroupEnabled" and "RouteTableEnabled"
delegations = map(object({
service_delegation_name = string
service_delegation_actions = list(string)
}))
security_rules = optional(map(object({
priority = number
direction = string
access = string
protocol = string
source_port_range = optional(string)
source_port_ranges = optional(list(string))
destination_port_range = optional(string)
destination_port_ranges = optional(list(string))
source_address_prefix = optional(string)
source_address_prefixes = optional(list(string))
destination_address_prefix = optional(string)
destination_address_prefixes = optional(list(string))
source_application_security_group_ids = optional(list(string))
})), {})
routes = optional(map(object({
address_prefix = string
next_hop_type = string
next_hop_in_ip_address = optional(string)
})))
}))
| n/a | yes | | [vnet\_address\_space](#input\_vnet\_address\_space) | Address space for the virtual network | `list(string)` | n/a | yes | diff --git a/modules/azure/networking/variables.tf b/modules/azure/networking/variables.tf index 85ff3c3..0dd5e01 100644 --- a/modules/azure/networking/variables.tf +++ b/modules/azure/networking/variables.tf @@ -26,6 +26,7 @@ variable "vnet_address_space" { variable "nat_prefix" { description = "Prefix of the nat gateway & public ip address" type = string + default = "" } variable "subnets" {