我对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}"
}
}下面是它需要运行的install-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中的上述脚本确实在后台运行命令。
有人能帮我处理缺失的部分吗?如何使用本地exec运行多个命令,如何消除警告消息?
感谢你的帮助,谢谢!
发布于 2021-04-29 00:22:24
我认为这里有两件事是不相关的。
这里的主要问题在于如何编写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关于仅插值表达式的警告消息与运行这些命令的问题无关。这告诉您,您已经使用了仍然支持向后兼容性但不再推荐的遗留语法。
如果您在编写本报告时正在使用Terraform的最新版本( v0.15版本之一或更高版本),那么您可以通过切换到此模块目录并运行terraform fmt来解决此问题和其他类似警告,这是一个更新配置以符合预期样式约定的命令。
或者,您可以手动更改该命令将自动更新的内容,即删除path.module周围的冗余内插标记。
working_dir = path.modulehttps://stackoverflow.com/questions/67297188
复制相似问题