0
votes

I have the following code:

resource "azurerm_public_ip" "imaged_pub_ip" {
  for_each = var.create_vm_images ? var.vms_to_image : {}
  name                = "${var.team_name}_${var.release}_imaged_public_ip_${each.value}"
  location            = var.loc
  resource_group_name = "${var.team_name}_${var.release}_${var.owner}_${var.intention}"
  allocation_method   = "Static"

  tags = {
    team = var.team_name
    environment = var.env_name
    useby = var.useby
    release = var.release
    devops_work_item_id = var.devops_work_item_id
    owner = var.owner
    intention = var.intention
  }
}
resource "azurerm_network_interface" "imaged_net_int" {
  for_each = var.create_vm_images ? var.vms_to_image : {}
  name                = "${var.team_name}_${var.release}_imaged_net_int_${each.value}"
  location            = var.loc
  resource_group_name = "${var.team_name}_${var.release}_${var.owner}_${var.intention}"

  ip_configuration {
    name                          = "eth0"
    private_ip_address_allocation = "Dynamic"
    subnet_id                     = data.azurerm_subnet.subnet.id
    public_ip_address_id          = values(azurerm_public_ip.imaged_pub_ip).*.id
  }

I am unable to reference the azurerm_public_ip.id in public_ip_address_id. It has an error: Inappropriate value for attribute "public_ip_address_id": string required.

I use a value map to say how many instances are required:

variable "vms_to_image" {
  type = map
}
  create_vm_images = "true"
  vms_to_image = {
    vm_id1 = "1"
    vm_id2 = "0"
  }

How do I reference the azurerm_public_ip.id for public_ip_address_id?

1

1 Answers

0
votes

This worked public_ip_address_id = azurerm_public_ip.imaged_pub_ip[each.key].id