I’m trying to create 8 interfaces, first 3 interface need public ip. I have public ip module where I create 3 public ips, and bind these when creating the interfaces. But I get errors like the ones below. Not sure why “ Inappropriate value for attribute “public_ip_address_id”: string required.” Error. Really appreciate if anyone can help. Thanks.
╷
│ Error: Incorrect attribute value type
│
│ on intfc/main.tf line 58, in resource “azurerm_network_interface” “virtual_network_interfaces”:
│ 58: public_ip_address_id = try(
│ 59: {
│ 60: for k1, v1 in var.public_ips :
│ 61: k1 => can(regex(“${each.value.name}”, v1.name)) ? v1.id : null
│ 62: },
│ 63: null)
│ ├────────────────
│ │ each.value.name is “Service_VPN_5”
│ │ var.public_ips is map of object with 3 elements
│
│ Inappropriate value for attribute “public_ip_address_id”: string required.
From Interface module
variable “public_ips” {
type = map(object({
name = string
id = string
}))
}
resource “azurerm_network_interface” “virtual_network_interfaces” {
for_each = var.interfaces
location = var.location
resource_group_name = var.resource_group_name
name = “{var.device_name}_{var.instance_type}_{var.site_name}_{each.value.name}_Interface”
enable_ip_forwarding = true
enable_accelerated_networking = true
ip_configuration {
name = “{var.device_name}_{var.instance_type}_{var.site_name}_{each.value.name}_IP_Config”
private_ip_address = each.value.address_prefixes[0]
private_ip_address_allocation = “Static”
# set Management interface as primary vNIC
primary = each.value.name == "Management" ? true : false
subnet_id = try(
lookup(
{ for k, v in var.subnets : v.name => v.id },
each.value.name, null
), null
)
public_ip_address_id = try(
{
for k1, v1 in var.public_ips :
k1 => can(regex("${each.value.name}", v1.name)) ? v1.id : null
},
null)
}
}
From Public IP Module
variable “interfaces” {
type = map(object({
name = string
address_prefixes = list(string)
id = string
public_ip_address_id = string
private_ip_address = list(string)
private_ip_addresses = list(string)
resource_group_name = string
virtual_machine_id = string
}))
}
resource “azurerm_public_ip” “public_ip_addresses” {
for_each = { for k, v in var.interfaces : k => v if !can(regex(“^Service”, v.name)) }
location = var.location
resource_group_name = var.resource_group_name
name = “${each.value.name}”
name = “{var.device_name}_{var.instance_type}_{var.site_name}_{each.value.name}_Interface_Public_IP”
allocation_method = “Static”
}