Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terraform 0.12+ index can be string or number #132

Closed
wants to merge 1 commit into from

Conversation

sysbot
Copy link

@sysbot sysbot commented Oct 30, 2019

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]
}

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]
}
```
@@ -125,7 +126,7 @@ func (r Resource) Tags() map[string]string {
t[kk] = vv
}
}
case "aws_instance", "linode_instance":
case "serverscom_dedicated_server", "aws_instance", "linode_instance":
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be a separate feature. Could you please split this into a separate PR?

@adammck
Copy link
Owner

adammck commented Dec 20, 2019

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

@sprnza
Copy link

sprnza commented Jan 3, 2020

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
Copy link
Contributor

atikhono commented Feb 5, 2020

@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
Copy link
Owner

adammck commented Feb 5, 2020

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

@adammck adammck closed this Feb 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants