Multiple File Provisioner in Json Terraform
"provisioner": {
    "file": {
        "connection": {
                "private_key": "${file(\"/KeyPair.pem\")}",
                "user": "id"
        },
        "content": "${template_file.x1}",
        "destination": "/path/to/dest1"

    },

    "file": {
            "connection": {
                    "private_key": "${file(\"/KeyPair.pem\")}",
                    "user": "id"
            },
            "content": "${template_file.x2}",
            "destination": "/path/to/dest2"
    }
}

Here I have a JSON Terraform scriplet. I understand I will have to merge/group the file provisioners but I am not too sure how to do that

I keep getting errors whilst validating.

SyntaxError: Duplicate key 'file' on line 78

Do I have to use inline feature?

I think this may be correct. Can anyone confirm?

"file": {
    "connection": {
        "private_key": "${file(\"/KeyPair.pem\")}",
        "user": "id"
    },
    "content": [
        "${template_file.1}",
        "${template_file.2}"
    ],
    "destination": [
        "/path/dest/",
        "/path/dest/"
    ]
}
1

1 Answer

Please go through the official sample here

So you should split the codes to two provisioner parts.

"provisioner": {
    "file": {
        "connection": {
                "private_key": "${file(\"/KeyPair.pem\")}",
                "user": "id"
        },
        "content": "${template_file.x1}",
        "destination": "/path/to/dest1"

    }
}

"provisioner": {
    "file": {
            "connection": {
                    "private_key": "${file(\"/KeyPair.pem\")}",
                    "user": "id"
            },
            "content": "${template_file.x2}",
            "destination": "/path/to/dest2"
    }
}

If there are a lot of files to be uploaded, provisioner file supports folder/directory upload. Please go through the details

If you got error message, please paste the detail error, otherwise, it's hard to give the suggestion.

4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

James H. Sterling

James H. Sterling

Environmental Science & Climate Journalist

James Sterling reports on renewable energy developments, climate policy, ecological conservation, and green tech innovations around the globe.

Share this article
Twitter Facebook Pinterest