【问题标题】:Using the script argument with remote-exec - terraform将脚本参数与远程执行一起使用 - terraform
【发布时间】:2021-10-15 05:10:48
【问题描述】:

我正在尝试将脚本参数与 remote-exec terraform Provisioner 一起使用。根据文档,脚本参数执行以下操作:

script - 这是一个本地脚本的路径(相对或绝对),将被复制到 远程资源,然后执行。这不能通过内联或脚本提供。

这是文档的链接: https://www.terraform.io/docs/language/resources/provisioners/remote-exec.html

代码如下:

    script = [
    "./scripts/provision.sh"
    ]

这是错误:

Error: Incorrect attribute value type

on main.tf line 86, in resource "vsphere_virtual_machine" "vm":
86:    script = [
87:      "./scripts/provision.sh",
88:    ]

Inappropriate value for attribute "script": string required.

任何帮助将不胜感激。

【问题讨论】:

    标签: terraform terraform0.12+


    【解决方案1】:

    我是 TF 的新手 - 脚本不采用列表,它是使用 [ ] 方括号定义的。解决方法是使用

    script = "./scripts/provision.sh"
    

    【讨论】:

      【解决方案2】:

      如果您查看文档,它会说:

      您不能使用脚本或脚本参数将任何参数传递给脚本。如果要指定参数,请使用文件配置器上传脚本,然后使用 inline 调用它。示例:

      resource "aws_instance" "web" {
        # ...
      
        provisioner "file" {
          source      = "script.sh"
          destination = "/tmp/script.sh"
        }
      
        provisioner "remote-exec" {
          inline = [
            "chmod +x /tmp/script.sh",
            "/tmp/script.sh args",
          ]
        }
      }
      

      另外,我建议在脚本/脚本上使用内联(我的个人偏好)。如果您需要使用不带括号的脚本。

      如果您在远程执行方面需要更多帮助,请告诉我。

      【讨论】:

        猜你喜欢
        • 2020-06-12
        • 1970-01-01
        • 1970-01-01
        • 2017-12-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-09-21
        • 1970-01-01
        相关资源
        最近更新 更多