Swe*_*rma 14 linux amazon-web-services terraform terraform-provider-aws
我是 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}"
}
}
Run Code Online (Sandbox Code Playgroud)
下面是需要运行的 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
Run Code Online (Sandbox Code Playgroud)
我收到以下警告:
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.
Run Code Online (Sandbox Code Playgroud)
main.tf 中的上述脚本确实在后台运行命令。
有人可以帮我解决缺失的部分吗?如何使用本地 exec 运行多个命令 另外,如何摆脱警告消息?
感谢您的所有帮助,谢谢!
Mar*_*ins 20
我认为这里发生了两件独立的事情,但实际上并不相关。
这里的主要问题在于你如何编写local-exec脚本:
command = <<EOT
"chmod +x install-istio.sh"
"./install-istio.sh"
EOT
Run Code Online (Sandbox Code Playgroud)
这将成为以下要运行的 shell 脚本:
"chmod +x install-istio.sh"
"./install-istio.sh"
Run Code Online (Sandbox Code Playgroud)
通过将第一个命令行放在引号中,您可以告诉 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
Run Code Online (Sandbox Code Playgroud)
有关仅插值表达式的警告消息与运行这些命令的问题无关。这表明您使用了旧语法,该语法仍受向后兼容性支持,但不再推荐。
如果您在撰写本文时使用的是最新版本的 Terraform(v0.15 版本之一或更高版本),那么您可以通过切换到此模块目录并运行来解决此警告和其他类似警告terraform fmt,即更新配置以匹配预期样式约定的命令。
或者,您可以手动更改该命令将自动更新的内容,即删除周围的冗余插值标记path.module:
working_dir = path.module
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
34068 次 |
| 最近记录: |