Skip to content

Commit 75276af

Browse files
authored
Merge pull request #9 from data-platform-hq/support_nat_gw_association
feat: support nat gw association
2 parents d85ea27 + b5cc5c2 commit 75276af

File tree

4 files changed

+33
-4
lines changed

4 files changed

+33
-4
lines changed

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ No modules.
2626
| Name | Type |
2727
|------|------|
2828
| [azurerm_subnet.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/subnet) | resource |
29+
| [azurerm_subnet_nat_gateway_association.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/subnet_nat_gateway_association) | resource |
2930
| [azurerm_subnet_network_security_group_association.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/subnet_network_security_group_association) | resource |
3031

3132
## Inputs
@@ -34,13 +35,16 @@ No modules.
3435
|------|-------------|------|---------|:--------:|
3536
| <a name="input_cidr"></a> [cidr](#input\_cidr) | The address prefixes to use for the subnet | `string` | n/a | yes |
3637
| <a name="input_delegations"></a> [delegations](#input\_delegations) | (optional) subnet delegation | <pre>list(object({<br> name = string<br> actions = list(string)<br> }))</pre> | `[]` | no |
38+
| <a name="input_export_subnet_id"></a> [export\_subnet\_id](#input\_export\_subnet\_id) | ID of already existing subnet. Provide this value to associate existing subnet with given Network Security Group | `string` | `null` | no |
3739
| <a name="input_name"></a> [name](#input\_name) | The name of the subnet | `string` | n/a | yes |
40+
| <a name="input_nat_gateway_association_enabled"></a> [nat\_gateway\_association\_enabled](#input\_nat\_gateway\_association\_enabled) | Boolean flag that determines if NAT Gateway association would be created | `bool` | `false` | no |
41+
| <a name="input_nat_gateway_id"></a> [nat\_gateway\_id](#input\_nat\_gateway\_id) | ID of the NAT Gateway which would be assigned to subnet | `string` | `null` | no |
3842
| <a name="input_network"></a> [network](#input\_network) | The name of the virtual network in which the subnet is created in | `string` | n/a | yes |
39-
| <a name="input_nsg_id"></a> [nsg\_id](#input\_nsg\_id) | The ID of the Network Security Group which should be associated with the Subnet | `map(string)` | {} | no |
43+
| <a name="input_nsg_association_enabled"></a> [nsg\_association\_enabled](#input\_nsg\_association\_enabled) | Boolean flag that determines if NSG association would be created | `bool` | `false` | no |
44+
| <a name="input_nsg_id"></a> [nsg\_id](#input\_nsg\_id) | The ID of the Network Security Group which should be associated with the Subnet | `string` | `null` | no |
4045
| <a name="input_private_endpoint_network_policies_enabled"></a> [private\_endpoint\_network\_policies\_enabled](#input\_private\_endpoint\_network\_policies\_enabled) | Enable or Disable network policies for the private link endpoint on the subnet. Setting this to true will Disable the policy and setting this to false will Enable the policy: [true\|false] | `bool` | `true` | no |
4146
| <a name="input_resource_group"></a> [resource\_group](#input\_resource\_group) | The name of the resource group in which to create the storage account | `string` | n/a | yes |
42-
| <a name="input_service_endpoints"></a> [service\_endpoints](#input\_service\_endpoints) | The list of Service endpoints to associate with the subnet: Microsoft.AzureActiveDirectory, Microsoft.AzureCosmosDB, Microsoft.ContainerRegistry, Microsoft.EventHub, Microsoft.KeyVault, Microsoft.ServiceBus, Microsoft.Sql, Microsoft.Storage, Microsoft.Web | `list(string)` | <pre>[<br> "Microsoft.Storage",<br> "Microsoft.KeyVault",<br> "Microsoft.Sql"<br>]</pre> | no |
43-
| <a name="input_export_subnet_id"></a> [export\_subnet\_id](#input\_export\_subnet\_id) | ID of already existing subnet. Provide this value to associate existing subnet with given Network Security Group | `string` | null | no |
47+
| <a name="input_service_endpoints"></a> [service\_endpoints](#input\_service\_endpoints) | The list of Service endpoints to associate with the subnet: Microsoft.AzureActiveDirectory, Microsoft.AzureCosmosDB, Microsoft.ContainerRegistry, Microsoft.EventHub, Microsoft.KeyVault, Microsoft.ServiceBus, Microsoft.Sql, Microsoft.Storage, Microsoft.Web | `list(string)` | <pre>[<br> "Microsoft.Storage",<br> "Microsoft.KeyVault",<br> "Microsoft.Sql",<br> "Microsoft.Web"<br>]</pre> | no |
4448

4549
## Outputs
4650

@@ -49,8 +53,9 @@ No modules.
4953
| <a name="output_address_prefixes"></a> [address\_prefixes](#output\_address\_prefixes) | The address prefixes to use for the subnet |
5054
| <a name="output_id"></a> [id](#output\_id) | The ID of the subnet |
5155
| <a name="output_name"></a> [name](#output\_name) | The name of the subnet |
56+
| <a name="output_name_to_id_map"></a> [name\_to\_id\_map](#output\_name\_to\_id\_map) | Map of Subnet Name to Id |
57+
| <a name="output_nat_gateway_association_id"></a> [nat\_gateway\_association\_id](#output\_nat\_gateway\_association\_id) | The ID of the NAT Gateway Association |
5258
| <a name="output_nsg_association_id"></a> [nsg\_association\_id](#output\_nsg\_association\_id) | The ID of the Network Security Group Association |
53-
| <a name="name_to_id_map"></a> [id](#output\_name\_to\_id\_map) | Map of Subnet Name to Id |
5459
<!-- END_TF_DOCS -->
5560

5661
## License

main.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,10 @@ resource "azurerm_subnet_network_security_group_association" "this" {
2626
subnet_id = var.export_subnet_id == null ? azurerm_subnet.this[0].id : var.export_subnet_id
2727
network_security_group_id = var.nsg_id
2828
}
29+
30+
resource "azurerm_subnet_nat_gateway_association" "this" {
31+
count = var.nat_gateway_association_enabled ? 1 : 0
32+
33+
subnet_id = var.export_subnet_id == null ? azurerm_subnet.this[0].id : var.export_subnet_id
34+
nat_gateway_id = var.nat_gateway_id
35+
}

outputs.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ output "nsg_association_id" {
1818
description = "The ID of the Network Security Group Association"
1919
}
2020

21+
output "nat_gateway_association_id" {
22+
value = try(azurerm_subnet_nat_gateway_association.this[0].id, null)
23+
description = "The ID of the NAT Gateway Association"
24+
}
25+
2126
output "name_to_id_map" {
2227
value = var.export_subnet_id == null ? { (azurerm_subnet.this[0].name) = azurerm_subnet.this[0].id } : null
2328
description = "Map of Subnet Name to Id"

variables.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,15 @@ variable "export_subnet_id" {
6161
description = "ID of already existing subnet. Provide this value to associate existing subnet with given Network Security Group"
6262
default = null
6363
}
64+
65+
variable "nat_gateway_association_enabled" {
66+
type = bool
67+
description = "Boolean flag that determines if NAT Gateway association would be created"
68+
default = false
69+
}
70+
71+
variable "nat_gateway_id" {
72+
type = string
73+
description = "ID of the NAT Gateway which would be assigned to subnet"
74+
default = null
75+
}

0 commit comments

Comments
 (0)