adammck / terraform-inventory

Terraform State → Ansible Dynamic Inventory
MIT License
1.82k stars 321 forks source link

Terraform 0.12+ index can be string or number #132

Closed sysbot closed 4 years ago

sysbot commented 5 years ago

In the case of when mixing resources into the statefile in terraform, it's now possible to have indexes that are not always int. In the example below using the new 0.12 syntax foreach will result in the index being mapped to the each.key name instead of the integer indexes.

variable "test" {
  default = {"testa" = "1.1.1.1", "testb" = "2.2.2.2"}
}

resource "aws_route53_record" "this" {
  for_each = var.test
  zone_id = "abc"
  name    = "${each.key}.tv."
  type    = "A"
  ttl     = "300"
  records = [each.value]
}
adammck commented 4 years ago

Thank you for the patch! Except for the comment above, this looks good to go.

sprnza commented 4 years ago

It doesn't work without changes in resource.go. So I get an error like this: couldn't parse resource keyName: vsphere_virtual_machine.win_slave.win-slave-1.10.178.3.74

atikhono commented 4 years ago

@sprnza Would you please try is my pull request fixed your issue?

@adammck I addressed your comment in my pull request. Could you please review additional changes in resource.go as well? I'm hitting this issue with string index too, would be really happy to have it fixed soon.

adammck commented 4 years ago

Merged #139, which includes this. Thanks very much for the original PR. Please re-open this if your issue isn't resolved.