Terraform - 无法在本地执行程序中 运行 多个命令

Terraform - Unable to run multiple commands in local exec

我是 Terraform 世界的新手。我正在尝试使用 Terraform 运行 shell 脚本。

下面是 main.tf 文件

#Executing shell script via Null Resource

resource "null_resource" "install_istio" {
 provisioner "local-exec" {
    command = <<EOT
      "chmod +x install-istio.sh"
      "./install-istio.sh"
    EOT
    interpreter = ["/bin/bash", "-c"]
    working_dir = "${path.module}"
  }
}

下面是 运行

所需的安装文件-istio.sh
#!/bin/sh

# Download and install the Istio istioctl client binary

# Specify the Istio version that will be leveraged throughout these instructions
ISTIO_VERSION=1.7.3

curl -sL "https://github.com/istio/istio/releases/download/$ISTIO_VERSION/istioctl-$ISTIO_VERSION-linux-amd64.tar.gz" | tar xz

sudo mv ./istioctl /usr/local/bin/istioctl
sudo chmod +x /usr/local/bin/istioctl

# Install the Istio Operator on EKS
istioctl operator init

# The Istio Operator is installed into the istio-operator namespace. Query the namespace.
kubectl get all -n istio-operator

# Install Istio components
istioctl profile dump default

# Create the istio-system namespace and deploy the Istio Operator Spec to that namespace.
kubectl create ns istio-system
kubectl apply -f istio-eks.yaml

# Validate the Istio installation
kubectl get all -n istio-system

我低于警告:

Warning: Interpolation-only expressions are deprecated
  on .terraform/modules/istio_module/Istio-Operator/main.tf line 10, in resource "null_resource" "install_istio":
  10:     working_dir = "${path.module}"
Terraform 0.11 and earlier required all non-constant expressions to be
provided via interpolation syntax, but this pattern is now deprecated. To
silence this warning, remove the "${ sequence from the start and the }"
sequence from the end of this expression, leaving just the inner expression.
Template interpolation syntax is still used to construct strings from
expressions when the template includes multiple interpolation sequences or a
mixture of literal strings and interpolations. This deprecation applies only
to templates that consist entirely of a single interpolation sequence.

main.tf 中的上述脚本在后台执行 运行 命令。

谁能帮我解决遗漏的部分?我如何使用 local exec 运行 多个命令另外,我如何摆脱警告消息?

感谢您的帮助,谢谢!

我认为这里发生了两件实际上不相关的事情。

这里的主要问题在于您如何编写 local-exec 脚本:

    command = <<EOT
      "chmod +x install-istio.sh"
      "./install-istio.sh"
    EOT

这将成为以下 shell 到 运行 的脚本:

"chmod +x install-istio.sh"
"./install-istio.sh"

通过将第一个命令行放在引号中,您告诉 shell 尝试 运行 一个名为 chmod +x install-istio.sh 的程序,不带任何参数。也就是说,shell 将尝试在您的 PATH 中找到一个名为 chmod +x install-istio.sh 的可执行文件,而不是尝试 运行 一个名为 chmod 的带有一些参数的命令正如我想的那样。

删除命令行周围的引号以使其工作。这里不需要引号,因为这些命令都不包含任何需要引号的特殊字符:

    command = <<-EOT
      chmod +x install-istio.sh
      ./install-istio.sh
    EOT

有关仅插值表达式的警告消息与 运行ning 这些命令的问题无关。这表明您使用了仍然支持向后兼容但不再推荐的旧语法。

如果您在撰写本文时使用的是最新版本的 Terraform(v0.15 版本之一或更高版本),那么您可以通过切换到此模块目录来解决此问题和其他类似的警告和 运行ning terraform fmt,这是一个更新配置以匹配预期样式约定的命令。

或者,您可以手动更改该命令将自动更新的内容,即删除 path.module:

周围的冗余插值标记
    working_dir = path.module