【发布时间】:2023-02-16 03:32:25
【问题描述】:
我需要通过 terraform VM 扩展 - 自定义脚本在 Azure Windows VM 中安装 Az.Storage 模块。其他命令都执行,但模块安装命令不执行。 资源“azurerm_virtual_machine_extension”“VMextn202”{
name = "avmextn1"
virtual_machine_id = azurerm_windows_virtual_machine.vm.id
publisher = "Microsoft.Compute"
type = "CustomScriptExtension"
type_handler_version = "1.9"
auto_upgrade_minor_version = true
settings = <<SETTINGS
{
"fileUris": ["https://${azurerm_storage_account.Storage.name}.blob.core.windows.net/${azurerm_storage_container.Scripts.name}/${azurerm_storage_blob.BlobVMExt.name}"],
"commandToExecute": "powershell -ExecutionPolicy Unrestricted -file VMExt.ps1"
}
SETTINGS
}
VMExt.ps1 的内容:
Get-Service | Out-File "C:\Users\Simulator-User\service.txt" -Force
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
Install-Module -Name Az.Storage -Force -AllowClobber -SkipPublisherCheck
Install-Module -Name Az.Storage -Force -AllowClobber -SkipPublisherCheck
在这里,第一个 cmd 执行(service.txt 正在 VM 中创建) 第二个 cmd 执行(包提供程序正在 VM 中安装) 但是下一个与模块安装相关的 cmd 没有被执行(无法从 Get-InstalledModules 中找到模块 - 模块没有安装在 VM 中)。
手动创建 VM 扩展 - Azure 门户中的自定义脚本也会发生同样的事情。
任何建议都会对我有所帮助。
【问题讨论】:
-
您能否尝试使用受保护的设置而不是设置。
-
谢谢你的建议。实际上我用不同的方法解决了它。
-
@ManojR 能否请您分享您使用的方法,我有类似的问题
-
我有同样的问题。
标签: azure terraform azure-virtual-machine powershell-az-module