Home > Back-end >  Can´t associate a Public IP to NAT Gateway on Terraform
Can´t associate a Public IP to NAT Gateway on Terraform

Time:01-21

The problem here is that following official Terraform documentation (v3.11) it´s impossible to associate a a Public IP id to the NAT Gateway body.

resource "azurerm_nat_gateway" "nat_gateway" {
    name                    = var.nat_gateway_name
    location                = "northeurope"
    resource_group_name     = var.resource_group_name
    public_ip_address_ids   = [azurerm_public_ip.pip.id]
    sku_name                = "Standard"
    idle_timeout_in_minutes = 10
    zones                   = ["1"] 
}

I tried hardcoding the ID value and creating a empty variable, but nothing worked.

The error message is:

│ Error: Unsupported argument
│ 
│   on ../modules/function-app-module/main.tf line 40, in resource "azurerm_nat_gateway" "nat_gateway":
│   40:   public_ip_address_ids   = [azurerm_public_ip.pip.id]
│ 
│ An argument named "public_ip_address_ids" is not expected here.

CodePudding user response:

The solution here is to associate the Public IP to to NAT Gateway using "azurerm_nat_gateway_public_ip_association". The code will be:

resource "azurerm_nat_gateway_public_ip_association" "nat_gateway_pip_association" {
  nat_gateway_id       = azurerm_nat_gateway.nat_gateway.id
  public_ip_address_id = azurerm_public_ip.pip.id
}
  • Related