gpt4 book ai didi

powershell - Terraform azurerm_virtual_machine_extension,使用 CustomScriptExtension 运行本地 PowerShell 脚本

转载 作者:行者123 更新时间:2023-12-05 08:39:16 29 4
gpt4 key购买 nike

如何在 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/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com