azure - 无法在 Windows VM 上使用 terraform 和 Azure VM 扩展自动映射 azure 存储共享

标签 azure azure-storage terraform azure-files azure-storage-files

问题陈述 我正在尝试使用 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/

相关文章:

azure - 为什么 Azure 建议使用用户委派共享访问签名

Azure Blob 存储 - 将存档的 blob 复制到在线层

azure - Terraform 强制替换 AKS 节点池而不进行任何更改

git - 无法使用服务主体从发布管道访问 Azure Devops Git 存储库

azure - 在 Azure 中运行 VM 只是为了下载到存储帐户

azure-devops - 特点 block 地形

azure - ARM 模板资源中的 if 条件

c# - 使用 key 在 azure 搜索索引中查找文档

php - 在每个实例上运行计划的 Azure PHP 脚本

.net - 在 Raspberry Pi 上调试 .NET 应用程序 - dotnet 已退出,代码为 0