Azure Network Public IP Association
This page shows how to write Terraform and Azure Resource Manager for Network Public IP Association and write them securely.
azurerm_nat_gateway_public_ip_association (Terraform)
The Public IP Association in Network can be configured in Terraform with the resource name azurerm_nat_gateway_public_ip_association
. The following sections describe 10 examples of how to use the resource and its parameters.
Example Usage from GitHub
resource "azurerm_nat_gateway_public_ip_association" "pip-assoc" {
count = var.create_public_ip ? 1 : 0
nat_gateway_id = azurerm_nat_gateway.natgw.id
public_ip_address_id = azurerm_public_ip.pip.0.id
}
resource "azurerm_nat_gateway_public_ip_association" "nat_gw_1" {
nat_gateway_id = azurerm_nat_gateway.main.id
public_ip_address_id = data.azurerm_public_ip.ip_1.id
}
resource "azurerm_nat_gateway_public_ip_association" "nat_gw_2" {
resource "azurerm_nat_gateway_public_ip_association" "pip_assoc" {
count = var.create_public_ip ? 1 : 0
nat_gateway_id = azurerm_nat_gateway.natgw.id
public_ip_address_id = azurerm_public_ip.pip[0].id
}
resource "azurerm_nat_gateway_public_ip_association" "public_ip" {
nat_gateway_id = var.nat_gateway_id
public_ip_address_id = var.public_ip_address_id
resource "azurerm_nat_gateway_public_ip_association" "dat_pip_assoc_01" {
nat_gateway_id = data.azurerm_nat_gateway.nat_gateway_01.id
public_ip_address_id = azurerm_public_ip.pip_01.id
}
resource "azurerm_nat_gateway_public_ip_association" "public_ip" {
nat_gateway_id = var.nat_gateway_id
public_ip_address_id = var.public_ip_address_id
resource "azurerm_nat_gateway_public_ip_association" "this" {
nat_gateway_id = azurerm_nat_gateway.natgw.id
public_ip_address_id = azurerm_public_ip.natpip.id
}
output "natpip" {
resource "azurerm_nat_gateway_public_ip_association" "example" {
nat_gateway_id = azurerm_nat_gateway.natgw.id
public_ip_address_id = azurerm_public_ip.natgw.id
}
resource "azurerm_subnet_nat_gateway_association" "nat" {
resource "azurerm_nat_gateway_public_ip_association" "natgw-pip-assoc" {
nat_gateway_id = azurerm_nat_gateway.natgw.id
public_ip_address_id = azurerm_public_ip.natgw-pip.id
resource "azurerm_nat_gateway_public_ip_association" "nat" {
nat_gateway_id = azurerm_nat_gateway.nat.id
public_ip_address_id = azurerm_public_ip.nat.id
}
Parameters
-
id
optional computed - string -
nat_gateway_id
required - string -
public_ip_address_id
required - string -
timeouts
single block
Explanation in Terraform Registry
Manages the association between a Nat Gateway and a Public IP.
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 Public IP Association?
Azure Network Public IP Association 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 Public IP Association?
For Terraform, the chintan-hashi/palo-ip-usecase, portefaix/portefaix and claranet/terraform-azurerm-nat-gateway 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.