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

Splats expanding improperly in provisioner #427

Closed
pushingice opened this issue Oct 16, 2014 · 9 comments
Closed

Splats expanding improperly in provisioner #427

pushingice opened this issue Oct 16, 2014 · 9 comments

Comments

@pushingice
Copy link

I'm trying to run a provisioner script against each instance in a count block. I would like to be able to send the list of all the DNS names in the block to each instance. It looks like what is happening is that instead of expanding the splat fully for every iteration (e.g. producing the list [0, 1]), it accumulates the list as it goes (e.g. [0], [0,1]). Sample config:

resource "aws_instance" "zookeeper" {
ami = "${var.amis}"
instance_type = "m3.large"
key_name = "daalt-experimental"
subnet_id = "subnet-ef5def86"
security_groups = ["${aws_security_group.dev-zookeeper.id}"]
availability_zone = "us-west-2b"
count = 2

tags {
Name = "daalt-zookeeper-dev-${count.index}"
}

provisioner "local-exec" {
command = "echo ${join(",",aws_instance.zookeeper.*.private_dns)} "
}
}

Here's the output:

aws_instance.zookeeper.0: Provisioning with 'local-exec'...
aws_instance.zookeeper.0 (local-exec): Executing: /bin/sh -c "echo ip-10-252-3-52.us-west-2.compute.internal "
aws_instance.zookeeper.0 (local-exec): ip-10-252-3-52.us-west-2.compute.internal
aws_instance.zookeeper.0: Creation complete
aws_instance.zookeeper.1: Provisioning with 'local-exec'...
aws_instance.zookeeper.1 (local-exec): Executing: /bin/sh -c "echo ip-10-252-3-52.us-west-2.compute.internal,ip-10-252-3-154.us-west-2.compute.internal "
aws_instance.zookeeper.1 (local-exec): ip-10-252-3-52.us-west-2.compute.internal,ip-10-252-3-154.us-west-2.compute.internal
aws_instance.zookeeper.1: Creation complete

@mitchellh
Copy link
Contributor

Notes: For this to work, we might actually have to split the graph into separate nodes for provisioners and resources, because the provisioners have to gate on all the resources being partially created.

@knuckolls
Copy link
Contributor

@mitchellh fwiw I think there's a lot of value in separating the resource creation and provisioning steps. I have thoughts and notes that I'm going to try to write up in a separate issue at some point.

@mitchellh
Copy link
Contributor

@knuckolls I agree, there is just some complication since we don't persist connection info and some other state. I'm not against it, just making notes of how we'd have to do it.

@pushingice
Copy link
Author

It would be nice to have a readable state file for the provisioners as well.

@mitchellh
Copy link
Contributor

@pushingice The state file is readable now! As of 0.3.0 it is human-readable JSON (non-compacted).

@pushingice
Copy link
Author

@mitchellh I don't think it is readable when the provisioner is kicked off though. I wrote a dynamic inventory script for ansible that reads the state file. I put this in my provisioner:

provisioner "local-exec" {
command = "ansible-playbook -i ./dynamic_inventory.py ..."
}

My python script dies when it tries to read from terraform.tfstate.

@mitchellh
Copy link
Contributor

@pushingice The state is updated only after Terraform is run. This I believe is working as expected (and not part of this issue).

@sethvargo sethvargo changed the title splats expanding improperly in provisioner Splats expanding improperly in provisioner Nov 19, 2014
@mitchellh
Copy link
Contributor

This is fixed by #1016

@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

No branches or pull requests

3 participants