Azure Network NAT Gateway
This page shows how to write Terraform and Azure Resource Manager for Network NAT Gateway and write them securely.
azurerm_nat_gateway (Terraform)
The NAT Gateway in Network can be configured in Terraform with the resource name azurerm_nat_gateway
. The following sections describe 10 examples of how to use the resource and its parameters.
Example Usage from GitHub
resource "azurerm_nat_gateway" "my_gateway" {
name = "nat-Gateway"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
public_ip_address_ids = [azurerm_public_ip.example.id]
public_ip_prefix_ids = [azurerm_public_ip_prefix.example.id]
resource "azurerm_nat_gateway" "ngw" {
depends_on = [azurerm_kubernetes_cluster.k8s, azurerm_kubernetes_cluster_node_pool.user]
name = local.nat-name
location = var.region_name
resource_group_name = azurerm_resource_group.resourcegroup.name
public_ip_prefix_ids = [ azurerm_public_ip_prefix.ngw.id ]
resource "azurerm_nat_gateway" "natgw" {
name = var.name
location = var.location
resource_group_name = var.resource_group_name
sku_name = "Standard"
resource "azurerm_nat_gateway" "natgw" {
name = "NATGW"
location = azurerm_resource_group.plspenat.location
resource_group_name = azurerm_resource_group.plspenat.name
sku_name = "Standard"
idle_timeout_in_minutes = 10
resource "azurerm_nat_gateway" "natgw" {
name = var.natgw_name
location = module.rg.rg_location
resource_group_name = module.rg.rg_name
sku_name = "Standard"
idle_timeout_in_minutes = 10
resource "azurerm_nat_gateway" "nat_gateway" {
name = var.name
location = var.location
resource_group_name = var.resource_group_name
}
resource "azurerm_nat_gateway" "natgw" {
name = "nat-Gateway"
location = data.azurerm_resource_group.natgw.location
resource_group_name = data.azurerm_resource_group.natgw.name
public_ip_address_ids = [azurerm_public_ip.natgw.id]
sku_name = "Standard"
resource "azurerm_nat_gateway" "nat-gw" {
name = "trake-nat-gateway"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
public_ip_address_ids = [azurerm_public_ip.p-ip.id]
public_ip_prefix_ids = [azurerm_public_ip_prefix.p-ip-px.id]
resource "azurerm_nat_gateway" "nat_vmms_outbound" {
resource_group_name = var.rg_name
location = var.location
name = "nat-vmss-outbound"
idle_timeout_in_minutes = 15
resource "azurerm_nat_gateway" "natgateway-marketplace-financial-prod" {
name = "natgateway-marketplace-financial-prod"
location = var.BRS
resource_group_name = azurerm_resource_group.Marketplace-financeiro-prod.name
public_ip_address_ids = [azurerm_public_ip.IP-Public-Marketplace-Financial-prod4.id]
sku_name = "Standard"
Parameters
-
id
optional computed - string -
idle_timeout_in_minutes
optional - number -
location
required - string -
name
required - string -
public_ip_address_ids
optional computed - set of string -
public_ip_prefix_ids
optional - set of string -
resource_group_name
required - string -
resource_guid
optional computed - string -
sku_name
optional - string -
tags
optional - map from string to string -
zones
optional - list of string -
timeouts
single block
Explanation in Terraform Registry
Manages a Azure NAT Gateway.
Tips: Best Practices for The Other Azure Network Resources
In addition to the azurerm_network_security_group, Azure Network has the other resources that should be configured for security reasons. Please check some examples of those resources and precautions.
azurerm_network_security_group
Ensure to disable RDP port from the Internet
It is better to disable the RDP port from the Internet. RDP access should not be accepted from the Internet (*, 0.0.0.0, /0, internet, any), and consider using the Azure Bastion Service.
azurerm_network_security_rule
Ensure to set a more restrictive CIDR range for ingress from the internet
It is better to set a more restrictive CIDR range not to use very broad subnets. If possible, segments should be divided into smaller subnets.
azurerm_network_watcher_flow_log
Ensure to enable Retention policy for flow logs and set it to enough duration
It is better to enable a retention policy for flow logs. Flow logs show us all network activity in the cloud environment and support us when we face critical incidents.
Microsoft.Network/natGateways (Azure Resource Manager)
The natGateways in Microsoft.Network can be configured in Azure Resource Manager with the resource name Microsoft.Network/natGateways
. The following sections describe how to use the resource and its parameters.
Example Usage from GitHub
"type": "Microsoft.Network/natGateways"
}
},
"201": {
"body": {
"name": "test-natGateway",
"type": "Microsoft.Network/natGateways"
}
},
"201": {
"body": {
"name": "test-natGateway",
"type": "Microsoft.Network/natGateways"
}
},
"201": {
"body": {
"name": "test-natGateway",
"type": "Microsoft.Network/natGateways"
}
},
"201": {
"body": {
"name": "test-natGateway",
"type": "Microsoft.Network/natGateways"
}
},
"201": {
"body": {
"name": "test-natGateway",
"type": "Microsoft.Network/natGateways"
}
},
"201": {
"body": {
"name": "test-natGateway",
"type": "Microsoft.Network/natGateways"
}
},
"201": {
"body": {
"name": "test-natGateway",
"type": "Microsoft.Network/natGateways"
}
},
"201": {
"body": {
"name": "test-natGateway",
"type": "Microsoft.Network/natGateways"
}
},
"201": {
"body": {
"name": "test-natGateway",
"type": "Microsoft.Network/natGateways"
}
},
"201": {
"body": {
"name": "test-natGateway",
Parameters
name
required - stringtype
required - stringapiVersion
required - stringlocation
required - stringResource location.
tags
optional - stringResource tags.
sku
optionalname
optional - stringName of Nat Gateway SKU.
properties
requiredidleTimeoutInMinutes
optional - integerThe idle timeout of the nat gateway.
publicIpAddresses
optional arrayid
required - stringResource ID.
publicIpPrefixes
optional arrayid
required - stringResource ID.
zones
optional - arrayA list of availability zones denoting the zone in which Nat Gateway should be deployed.
Frequently asked questions
What is Azure Network NAT Gateway?
Azure Network NAT Gateway is a resource for Network of Microsoft Azure. Settings can be wrote in Terraform.
Where can I find the example code for the Azure Network NAT Gateway?
For Terraform, the gilyas/infracost, akapernaros/iac_azure_aks and YipCyrus/terraform source code examples are useful. See the Terraform Example section for further details.
For Azure Resource Manager, the jashsing-mic/azure-rest-api-specs, jashsing-mic/azure-rest-api-specs and jashsing-mic/azure-rest-api-specs source code examples are useful. See the Azure Resource Manager Example section for further details.