Terraform keep complaining duplicate block while creating azure vpn gateway using terraform

Viewed 23

Objective: Trying to create vpn gateway using terraform on Azure

What I tried:

resource "azurerm_virtual_network_gateway" "vpn-gw" {
  name = "vng-orpcb-hub-${var.env}-we"
  location = azurerm_resource_group.rg[0].location
  resource_group_name = azurerm_resource_group.rg[0].name
  type = "Vpn"
  vpn_type = "RouteBased"
  active_active = true
  enable_bgp = false
  sku = "VpnGw1AZ"
  ip_configuration {
    name = "vnetGatewayConfig"
    public_ip_address_id = azurerm_public_ip.vpn-gateway-ip.id    
    private_ip_address_allocation = "Dynamic"
    subnet_id = data.azurerm_subnet.gatewaysubnetdata.id
  }
  ip_configuration {
    name = "vnetGatewayConfig1"
    public_ip_address_id = azurerm_public_ip.vpn-gateway-ip-secondary.id
    private_ip_address_allocation = "Dynamic"
    subnet_id = data.azurerm_subnet.gatewaysubnetdata.id
  }
  ip_configuration {
    name = "vnetGatewayConfig2"
    public_ip_address_id = azurerm_public_ip.vpn-gateway-ip-vpn.id
    private_ip_address_allocation = "Dynamic"
    subnet_id = data.azurerm_subnet.gatewaysubnetdata.id
  }

  dynamic "vpn_client_configuration" {
    for_each = tomap({ for k, v in var.audience : k => v })
    content {
    address_space = ["10.100.0.0/24"]
    vpn_auth_types = ["AAD"]
    aad_tenant = "https://login.microsoftonline.com/xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    aad_audience = vpn_client_configuration.value
    aad_issuer = "https://sts.windows.net/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/"
    }  
  }
}

My variable.tf:

variable "audience" {
  description = "respective environments"
  type = any
  default = {
    dev = "41b23e61-6c1e-4545-b367-cd054e0ed4b4"
    stg = "41b23e61-6c1e-4545-b367-cd054e0ed4b4"
    prod = "41b23e61-6c1e-4545-b367-cd054e0ed4b4"
}
}

Error I am getting is:

Error: Too many vpn_client_configuration blocks
│ 
│   on main.tf line 933, in resource "azurerm_virtual_network_gateway" "vpn-gw":
│  933:     content {
│ 
│ No more than 1 "vpn_client_configuration" blocks are allowed

I am not sure where I am giving multiple client configuration here

I am trying to pass in audience value from that variable map based on environment code that i pass, i.e dev,stg,prod etc

Please suggest.

1 Answers

I have solved it. Removed for_each and just audience = var.audience[var.env] Thanks for suggestions.

Related