pretf
pretf copied to clipboard
[question] Is adding a provisioner to a resource possible?
Is it possible to add a provisoner inside a resource like the Puppet provisoner or the remote-exec prov?
https://www.terraform.io/docs/provisioners/puppet.html
I don't see a mention of this, and i've been playing around with it for a little while with no luck.
Thanks!
Hi @ffalorjr,
I made main.tf containing the following and was able to do a plan. It didn't show the provisioner in the plan but I think it's right because when I introduced a typo into the word provisioner it failed.
from pretf.api import block
def pretf_blocks():
yield block("provider", "aws", {
"profile": "pretf-nonprod", # specific to my ~/.aws files
"region": "eu-west-1",
})
yield block("resource", "aws_instance", "web", {
"ami": "xyz",
"instance_type": "t3.nano",
"provisioner": {
"puppet": {
"server": "test",
"server_user": "ubuntu",
"extension_requests": {
"pp_role": "webserver",
},
},
},
})
Please let me know if it works or not (without the dummy values of course).
I'll label this as documentation, since translating nested HCL blocks into Python dicts / JSON is not super obvious. If it doesn't work then we can try to figure that out too.
The JSON it exports looks exactly like the sample terraform gives. I don't have time right this moment to get the connection piece working, but this looks like it does exactly what I wanted it to do. Next week when I have time to test I'll report back.
Thank you!
Someone also asked me how nested blocks work (just 1 level deep) so the docs should have some more examples including a provisioner (2 levels) and something else with 1 level.
Another question about nested blocks: #52