【发布时间】:2021-07-21 15:07:47
【问题描述】:
我是 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 运行多个命令另外,如何摆脱警告消息?
感谢您的帮助,谢谢!
【问题讨论】:
-
要摆脱警告,只需从
working_dir = "${path.module}"中省略"${和}",即working_dir = path.module。下一个问题,你是说install-istio.sh没有被执行?有错误提示吗? -
您是否正在使用 GKE?
标签: linux amazon-web-services terraform terraform-provider-aws