powershell - Terraform azurerm_virtual_machine_ext

如何在 terraform azurerm_virtual_machine_extension 中运行本地(不存储到 blob 存储帐户)PowerShell 脚本

文件夹有

  1. main.tf
  2. 安装.ps1

    资源“azurerm_virtual_machine_extension”“软件”{ name = "安装软件" resource_group_name = azurerm_resource_group.azrg.name virtual_machine_id = azurerm_virtual_machine.vm.id publisher = "Microsoft.Compute" type = "CustomScriptExtension" type_handler_version = "1.9"

      settings = <<SETTINGS
        { 
          "commandToExecute": "powershell -ExecutionPolicy Unrestricted -File \"install.ps1\""
        } 
        SETTINGS
    } 
    

    但失败了

    [
            {
                "code": "ComponentStatus/StdOut/succeeded",
                "level": "Info",
                "displayStatus": "Provisioning succeeded",
                "message": "Windows PowerShell \r\nCopyright (C) Microsoft Corporation. All rights reserved.\r\n\r\n"
            },
            {
                "code": "ComponentStatus/StdErr/succeeded",
                "level": "Info",
                "displayStatus": "Provisioning succeeded",
                "message": "The argument 'install.ps1' to the -File parameter does not exist. Provide the path to an existing '.ps1' file as an argument to the -File parameter.\r\n"
            }
        ]
    

任何线索。

谢谢

最佳答案

这对我有用。

resource "azurerm_virtual_machine_extension" "software" {
  name                 = "install-software"
  resource_group_name  = azurerm_resource_group.azrg.name
  virtual_machine_id   = azurerm_virtual_machine.vm.id
  publisher            = "Microsoft.Compute"
  type                 = "CustomScriptExtension"
  type_handler_version = "1.9"

  protected_settings = <<SETTINGS
  {
    "commandToExecute": "powershell -command \"[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String('${base64encode(data.template_file.tf.rendered)}')) | Out-File -filepath install.ps1\" && powershell -ExecutionPolicy Unrestricted -File install.ps1"
  }
  SETTINGS
}

data "template_file" "tf" {
    template = "${file("install.ps1")}"
} 

关于powershell - Terraform azurerm_virtual_machine_extension,使用 CustomScriptExtension 运行本地 PowerShell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60265902/

相关文章:

python - 如何在python中创建文件夹?

ios - 从 XCode 的调试导航器中清除崩溃日志

list - 得到 "Fatal error: Index out of range": show

typescript - typescript 中的 bool 列表是否有 "all"或 "any"

amazon-web-services - 使用 axios 和 aws4 向 aws 进行身份验证

javascript - 运算符 '<' 不能应用于类型 'Date' 和 'number' .ts

sql - 我如何允许sql中的重复值?

javascript - 如何模拟 axios.create([config]) 函数以返回其实例方

oracle - 在 Apex 中提交表单之前添加确认

three.js - 如何使用 threejs 在 iPhone 上启用视网膜分辨率 render.