'Outputting information after provisioning a vm with terraform?
I have a set of vm instance I want to provision with terraform.
Each VM will need the information from the previous one in the chain - during setup a unique key is created for a peering app.
Thoughts about the approach:
- read the information from (write to disk) and put it as the single page of a simple web server
- output something using local-exec, remote-exec
- Something else?
That is to say, I need non-standard (where standard is something like an IP address, hostname) output by a service started after provisioning, that I can then pass to later provisioners. It's getting the output that is the issue, not the dependency.
Solution 1:[1]
Terraform has in built functionality to maintain dependencies.
Perhaps you can create the keys as separate resources, and then reference them in both linked vm's ?
Or if not maybe the key that is created can be exported in TF ? Then you can reference it in another VM resource, and TF will be smart enough to first build the first one, then the second.
There probably is a TF solution for your problem, without having to hack around too much. Already local-exec is a last resort kind of thing.
Solution 2:[2]
FWIW, I ended up stripping all the provisioners out of the terraform, and just built a simple script, the first step of which was to execute the terraform apply, and then did the rest with simple remote script execution over ssh. Ugly, but it worked.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Chai |
| Solution 2 | aronchick |
