问题陈述 我正在尝试使用 Azure VM 扩展自动将 Azure 文件共享映射到 Windows VM。 VM 扩展安装成功,命令运行,但在登录 VM 时,我看到我的驱动器已断开连接。
在尝试访问它时,我收到不正确的用户名或密码错误。但是,在计算机上运行 PowerShell 脚本可以正确映射网络驱动器,并且我可以访问它。
代码
resource "azurerm_virtual_machine_extension" "test" {
# Custom VM extension documentation https://learn.microsoft.com/en-us/azure/virtual-machines/extensions/custom-script-windows
# additional documentation http://teknews.cloud/bootstrapping-azure-vms-with-terraform/, https://github.com/terraform-providers/terraform-provider-azurerm/issues/728
name = "network_share"
location = "${azurerm_resource_group.main.location}"
resource_group_name = "${azurerm_resource_group.main.name}"
#virtual_machine_name = "${azurerm_virtual_machine.vm.name}"
virtual_machine_name = "${element(azurerm_virtual_machine.vm.*.name, count.index)}"
publisher = "Microsoft.Compute"
type = "CustomScriptExtension"
type_handler_version = "1.9"
count = "${var.vm_count}"
settings = <<SETTINGS
{
"commandToExecute": "powershell -command \"[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String('${base64encode(data.template_file.net_fileshare_script.rendered)}')) | Out-File -filepath net_fileshare_script.ps1\" && powershell -File net_fileshare_script.ps1"
}
SETTINGS
depends_on = ["azurerm_virtual_machine.vm"]
}
data "template_file" "net_fileshare_script" {
template = "${file("./scripts/net_fileshare_script.ps1")}"
}
最佳答案
我发现脚本按原样工作。问题是远程用户登录后无法使用存储共享的凭据。
远程用户登录后,运行此命令
调用表达式-命令“cmdkey/add:storageaccount.file.core.windows.net/user:AZURE\storageaccount/pass:storagekey”
使远程用户帐户可以访问存储共享。
注意:是否可以通过一次性脚本为多个用户帐户提供一个凭据?
关于azure - 无法在 Windows VM 上使用 terraform 和 Azure VM 扩展自动映射 azure 存储共享,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55219879/