使用terraform在GCP计算引擎中安装kubectl



需要在terraform脚本中的metadata_startup_script中添加多个命令才能在GCP中启动compute engine实例

以下是我的代码

metadata_startup_script = "curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl" ; chmod +x kubectl ; sudo cp kubectl /usr/local/bin"

terraform plan显示以下错误

Error: Missing newline after argument
on main.tf line 58, in resource "google_compute_instance" "default":
58: metadata_startup_script = "curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl" ; chmod +x kubectl ; sudo cp kubectl /usr/local/bin"
An argument definition must end with a newline.

有什么解决问题的建议吗?任务是在使用以下命令启动compute engine后安装kubectl

curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl" 
chmod +x kubectl 
sudo cp kubectl /usr/local/bin"

您有两个解决方案

  1. 转义双引号">
metadata_startup_script = "curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl" ; chmod +x kubectl ; sudo cp kubectl /usr/local/bin"
  1. 在TF文件中用多行编写脚本
metadata_startup_script = <<SCRIPT
curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl" 
chmod +x kubectl 
sudo cp kubectl /usr/local/bin
SCRIPT

相关内容

  • 没有找到相关文章

最新更新