简体   繁体   English

Terraform GCP - Arguments 传入 windows-startup-script-ps1

[英]Terraform GCP - Arguments pass in windows-startup-script-ps1

In Terraform for GCP VM provision, I need to Run PowerShell script for disk partition as a startup.在 Terraform 中用于 GCP VM 配置,我需要为磁盘分区运行 PowerShell 脚本作为启动。 It requires 2 arguments as array for DriveName & DriveLetters.它需要 2 arguments 作为 DriveName 和 DriveLetters 的数组。

    windows-startup-script-ps1 = "${file("disk.ps1") ('Logs','Files') ('M','S')"

it doesn't work, can you help how to give arguments to Powershell in Terraform startup script for VM provision.它不起作用,你能帮助如何在 Terraform 启动脚本中将 arguments 提供给 Powershell 以提供 VM。

Thanks.谢谢。

As the public documentation from GCP about startup scripts on Windows VM the metadata keys that can be used for the disk partition needs to be the correct as the following, you need to compare if is need it to execute a command or a script.由于 GCP 关于Windows VM 上的启动脚本的公开文档,可用于磁盘分区的元数据密钥需要如下所示正确,您需要比较是否需要它来执行命令或脚本。

在此处输入图像描述

To declare the metadata in the main.tf file can be used the next block as an example.要在 main.tf 文件中声明元数据,可以使用下一个块作为示例。

  metadata = {
    windows-startup-script-cmd = <<-EOF
      "$${file("disk.ps1") ('Logs','Files') ('M','S')"
    EOF
  }

This is an argument inside the google_compute_instance block.这是google_compute_instance块中的一个参数。

Multiline strings can use shell-style "here doc" syntaxin terraform, with the string starting with a marker like <<-EOF and then the string ending with EOF on a line of its own.多行字符串可以在 terraform 中使用 shell 样式的“here doc”语法,字符串以 <<-EOF 之类的标记开头,然后字符串以 EOF 结束在它自己的一行中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM