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

Variable interpolation of a multiple instance resource #636

Closed
Nalum opened this issue Dec 10, 2014 · 6 comments · Fixed by #988
Closed

Variable interpolation of a multiple instance resource #636

Nalum opened this issue Dec 10, 2014 · 6 comments · Fixed by #988
Assignees

Comments

@Nalum
Copy link

Nalum commented Dec 10, 2014

I'm creating this as a separate issue to #633.

When using the following syntax ${aws_instance.api.*.public_ip} in the local-exec provisioner it will create the following string when it's running for the second instance:

54.166.168.91
54.166.147.56B780FFEC-B661-4EB8-9236-A01737AD98B654.166.168.91

The resource is as follows:

resource "aws_instance" "api" {
    ami = "${lookup(var.aws-amis, var.aws-region)}"
    instance_type = "${var.aws-instance-type}"
    ebs_optimized = true
    key_name = "${lookup(var.aws-keys, var.aws-region)}"

    security_groups = [
        "${aws_security_group.api.name}"
    ]

    tags = {
        Name = "API"
    }

    provisioner "local-exec" {
        command = "echo ${aws_instance.api.*.public_ip} >> public_ips"
    }

    count = 2
}
@armon
Copy link
Member

armon commented Dec 10, 2014

Hmm this is interesting... I think this should cause an error. This means that every aws_instance.api depends on every other aws_instance.api. There is no sane way for TF to handle that dependency AFAIK.

@Nalum
Copy link
Author

Nalum commented Dec 11, 2014

Just to make sure it is clear, as reading over it again it may not have been.

The second instance creates this string: 54.166.147.56B780FFEC-B661-4EB8-9236-A01737AD98B654.166.168.91

@mitchellh
Copy link
Contributor

Theoretically this is possible, but not without major internal refactoring of Terraform. In the short term, I believe we should at least validate this as an error, and I'll make this the goal of this issue.

@MerlinDMC
Copy link
Contributor

For me the problem is more that the interpolation delimiter (

const InterpSplitDelim = `B780FFEC-B661-4EB8-9236-A01737AD98B6`
) made it into the output somehow ... which afaik should not be possible/happen.

I use the interpolation to get all IPs of a resource itself as well since for me it is not an error if you get the list of known IPs at the time of evaluation. (I preset cassandra seeds via ${join(",",instance.cassandra.*.private_ip)})

In the case where only the first instance is created I get a single IP and that list expands while other instances come up.

@mitchellh
Copy link
Contributor

Note you can use the join function which @MerlinDMC mentioned to get the behavior you want.

@ghost
Copy link

ghost commented May 4, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators May 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants