JSON Terraform 中的多个文件配置器

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"
    }
}

这里我有一个 JSON Terraform scriplet。我知道我必须 merge/group 文件配置器,但我不太确定该怎么做

我在验证时不断出错。

SyntaxError: Duplicate key 'file' on line 78

我必须使用内联功能吗?

我认为这可能是正确的。谁能确认一下?

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

请看官方样本here

所以你应该把代码分成两个供应商部分。

"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"
    }
}

如果要上传的文件很多,provisioner file支持folder/directory上传。请查看详细信息

https://www.terraform.io/docs/provisioners/file.html#directory-uploads

如果您收到错误消息,请粘贴详细错误,否则很难给出建议。