terraform-coop / terraform-provider-foreman

Terraform provider for Foreman
https://registry.terraform.io/providers/terraform-coop/foreman
Mozilla Public License 2.0
33 stars 31 forks source link

foreman_host.name[index].interfaces_attributes is empty list of object #108

Closed togoschi closed 1 year ago

togoschi commented 1 year ago

With v0.5.x the interface_attribute[index].ip attribute of all host resources are emtpy when running terraform apply for the first time. If you run tf apply for the second time after all foreman_host resources are created the issue disappears.

An example output when foreman_host.osd[0] resource only is applied (and foreman_host.osd[1] already exists)

╷
│ Error: Invalid index
│ 
│   on variables.tf line 141, in locals:
│  141:   mgr_ips = formatlist("%s", concat(tolist([foreman_host.osd[0].interfaces_attributes[0].ip, foreman_host.osd[1].interfaces_attributes[0].ip]))
│     ├────────────────
│     │ foreman_host.osd[0].interfaces_attributes is empty list of object
│ 
│ The given key does not identify an element in this collection value.
╵
time=2023-01-11T17:57:05+01:00 level=error msg=1 error occurred:
        * exit status 1

Terraform Code

locals {
  mgr_ips = formatlist("%s", tolist([foreman_host.osd[0].interfaces_attributes[0].ip, foreman_host.osd[1].interfaces_attributes[0].ip]))
}

resource "foreman_host" "osd" {
  count      = var.osd.count
  name       = format(var.osd.hostname_format, count.index + 1)
  build      = true
  managed    = true
  enable_bmc = false

  interfaces_attributes {
    type      = "interface"
    primary   = true
    provision = true
    managed   = true
    subnet_id = data.foreman_subnet.hcp-infra.id
    compute_attributes = {
      "network" = var.vsphere_client_network
    }
  }

  interfaces_attributes {
    type      = "interface"
    primary   = false
    provision = false
    managed   = true
    compute_attributes = {
      "network" = var.vsphere_cluster_network
    }
  }
agriffit79 commented 1 year ago

I know what the problem is. I am working on a fix.

thatsk commented 1 year ago

this is still issue i just checked its not working

agriffit79 commented 1 year ago

I was able to re-create the issue and the fix resolved for me.

@togoschi - were you able to test it?

togoschi commented 1 year ago

@agriffit79 Yes, the issue is fixed in v0.5.8