簡體   English   中英

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片段。 我知道我必須合並/分組文件配置程序,但我不太確定該怎么做

驗證時,我不斷收到錯誤消息。

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

在這里查看官方樣本

因此,您應該將代碼分為兩個供應商部分。

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

如果要上傳的文件很多,則預配器file支持文件夾/目錄上傳。 請詳細說明

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

如果收到錯誤消息,請粘貼詳細錯誤,否則,很難給出建議。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM