You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#Customer intent: As a network administrator, I want to learn how to create and remove a NAT gateway resource from a virtual network subnet. I also want to learn how to add and remove public IP addresses and prefixes used for outbound connectivity.
12
12
---
13
13
@@ -91,11 +91,25 @@ To use Azure CLI for this article, you need:
91
91
92
92
- The example NAT gateway is named **nat-gateway**.
93
93
94
+
# [**Terraform**](#tab/manage-nat-terraform)
95
+
96
+
- An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/pricing/purchase-options/azure-account?cid=msft_learn).
97
+
98
+
- An existing Azure Virtual Network and subnet. For more information, see [Quickstart: Create a virtual network using the Azure portal](../virtual-network/quick-create-portal.md).
99
+
100
+
- The example virtual network that is used in this article is named **vnet-1**.
101
+
102
+
- The example subnet is named **subnet-1**.
103
+
104
+
- The example NAT gateway is named **nat-gateway**.
105
+
106
+
-[Installation and configuration of Terraform](/azure/developer/terraform/quickstart-configure).
107
+
94
108
---
95
109
96
110
## Create a NAT gateway and associate it with an existing subnet
97
111
98
-
You can create a NAT gateway resource and add it to an existing subnet by using the Azure portal, Azure PowerShell, Azure CLI, or Bicep.
112
+
You can create a NAT gateway resource and add it to an existing subnet by using the Azure portal, Azure PowerShell, Azure CLI, Bicep, or Terraform.
To create a NAT gateway with a public IP address, create a file named *main.tf* with the following Terraform configuration. The configuration creates a StandardV2 public IP address, a StandardV2 NAT gateway, and associates the NAT gateway with an existing subnet.
443
+
444
+
> [!NOTE]
445
+
> The `zones` argument must be omitted when `sku_name` is set to `StandardV2`. StandardV2 NAT gateways are zone-redundant by default.
To remove a NAT gateway from a subnet and delete the resource, remove the `azurerm_subnet_nat_gateway_association`, `azurerm_nat_gateway`, and any associated public IP resources from your Terraform configuration, then apply the changes.
661
+
662
+
If you only want to remove the NAT gateway association from the subnet, remove the `azurerm_subnet_nat_gateway_association` resource from your configuration:
663
+
664
+
```hcl
665
+
# Remove this resource block from your configuration to disassociate the NAT gateway from the subnet
To delete the NAT gateway and all its associations, remove the NAT gateway and all association resource blocks from your configuration. Run the following commands to apply the changes:
673
+
674
+
```terraform
675
+
terraform plan
676
+
terraform apply
677
+
```
678
+
550
679
---
551
680
552
681
> [!NOTE]
@@ -736,6 +865,43 @@ az network nat gateway update \
736
865
737
866
Use the Azure portal, Azure PowerShell, or Azure CLI to add or remove a public IP address from a NAT gateway.
738
867
868
+
# [**Terraform**](#tab/manage-nat-terraform)
869
+
870
+
### Add public IP address
871
+
872
+
To add a public IP address to the NAT gateway, add a new `azurerm_public_ip` resource and a new `azurerm_nat_gateway_public_ip_association` resource to your Terraform configuration.
873
+
874
+
In this example, the existing public IP address associated with the NAT gateway is named **public-ip-nat**.
To remove a public IP address from the NAT gateway, remove the corresponding `azurerm_nat_gateway_public_ip_association` resource block from your configuration. You can also remove the `azurerm_public_ip` resource if it's no longer needed.
897
+
898
+
Run the following commands to apply the changes:
899
+
900
+
```terraform
901
+
terraform plan
902
+
terraform apply
903
+
```
904
+
739
905
---
740
906
741
907
## Add or remove a public IP prefix
@@ -922,6 +1088,42 @@ az network nat gateway update \
922
1088
923
1089
Use the Azure portal, Azure PowerShell, or Azure CLI to add or remove a public IP prefix from a NAT gateway.
924
1090
1091
+
# [**Terraform**](#tab/manage-nat-terraform)
1092
+
1093
+
### Add public IP prefix
1094
+
1095
+
To add a public IP prefix to the NAT gateway, add a new `azurerm_public_ip_prefix` resource and a new `azurerm_nat_gateway_public_ip_prefix_association` resource to your Terraform configuration.
1096
+
1097
+
In this example, the existing public IP prefix associated with the NAT gateway is named **public-ip-prefix-nat**.
To remove a public IP prefix from the NAT gateway, remove the corresponding `azurerm_nat_gateway_public_ip_prefix_association` resource block from your configuration. You can also remove the `azurerm_public_ip_prefix` resource if it's no longer needed.
0 commit comments