需要在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"
您有两个解决方案
- 转义双引号">
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"
- 在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