pretf icon indicating copy to clipboard operation
pretf copied to clipboard

[question] Is adding a provisioner to a resource possible?

Open ghost opened this issue 5 years ago • 4 comments

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!

ghost avatar Mar 04 '20 19:03 ghost

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.

raymondbutcher avatar Mar 05 '20 21:03 raymondbutcher

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!

ghost avatar Mar 05 '20 22:03 ghost

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.

raymondbutcher avatar Mar 06 '20 09:03 raymondbutcher

Another question about nested blocks: #52

raymondbutcher avatar Mar 30 '20 16:03 raymondbutcher