Skip to content

Instantly share code, notes, and snippets.

@nrvale0
Last active May 31, 2017 23:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nrvale0/c64589071eb3ac60ce3db1332dc5312a to your computer and use it in GitHub Desktop.
Save nrvale0/c64589071eb3ac60ce3db1332dc5312a to your computer and use it in GitHub Desktop.
Array of instance IDs to aws_elb 'instance'

Sushain,

The behavior you describe around the 0th instance is strange but, regardless, I think an element() expression is not the correct approach here. Mocking things up a bit...

$ mkdir -p /tmp/terraform && cd /tmp/terraform
$ cat << EOF > test.tf
variable "instances_as_output" {
  default = "i-94834,i-98454,i-98342"
}
EOF
$ terraform console
> "${split(",", var.instances_as_output)}"
[
  i-94834,
  i-98454,
  i-98342
]
>  ^D

To get a List of instance IDs from your join()-packed output, which I've mocked as the variable 'instances_as_output', we simply take the result of the split() function as shown by 'terraform console' above.

The Terraform AWS Provider Resource 'aws_elb' has a field 'instances' which then accepts an array:

https://www.terraform.io/docs/providers/aws/r/elb.html#instances

I think its just a matter of passing the results of our split to the 'instances' attribute.

Does that make sense?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment