Review public IP associations on Azure network interfaces

Check whether the workload needs a directly associated public IP.

Description

Setting public_ip_address_id associates a public IP address with an Azure network interface.

Potential impact

Internet clients can reach listening services when routing, network security groups (NSGs), and the host firewall permit it.

Remediation

If direct public access is unnecessary, establish a management path first, then remove public_ip_address_id from ip_configuration. If you keep the address, allow only the required ports and sources.

Examples

Supply a public IP resource ID for the Before example. Both examples use dynamic private IP allocation.

Before

hcl
resource "azurerm_network_interface" "example" {
  name                = "example-nic"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name

  ip_configuration {
    name                          = "internal"
    subnet_id                     = azurerm_subnet.example.id
    private_ip_address_allocation = "Dynamic"
    public_ip_address_id          = var.public_ip_address_id
  }
}

After

hcl
resource "azurerm_network_interface" "example" {
  name                = "example-nic"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name

  ip_configuration {
    name                          = "internal"
    subnet_id                     = azurerm_subnet.example.id
    private_ip_address_allocation = "Dynamic"
  }
}

References