Issue mounting Azure FileShare with azurerm_windows_virtual_machine_scale_set

113 views Asked by At

I am facing the same issue and trying the solution here I use terraform with azurerm with customScriptExtension in azurerm_windows_virtual_machine_scale_set such


  resource "azurerm_windows_virtual_machine_scale_set" "example" {
  count               = 1
  name                = "example"
  location            = "mylocation"
  resource_group_name = "myRG"
  
  identity {
    type = "SystemAssigned"
  }

  enable_automatic_updates = true
  computer_name_prefix = "myexample"
  instances           = 1
  sku                = int
  admin_username      = "myadmin"
  admin_password      = "mypass"
  source_image_id = data.azurerm_shared_image_version.edi_image_backend_version.id
 
  extension_operations_enabled = true

    extension {
      name                         = "EDI-CustomScript"
      publisher                    = "Microsoft.Compute"
      type                         = "CustomScriptExtension"
      type_handler_version         = "1.10"
      settings = <<SETTINGS
      {
        "fileUris": [
          "${file.url}",
          "${psexec.url}"
        ],
         "commandToExecute" : "powershell -Command \"Enable-PSRemoting -Force\" ;.\\psexec -u ${USER} -p ${PASS} -accepteula -nobanner -s -h  powershell.exe -File ${file.name} -StorageAccountAccessKey ${AccesKey} -FileShare ${fileshare} -StorageAccount ${storageaccount.name}"
     }
      SETTINGS
    protected_settings = <<SETTINGS
        {
          "storageAccountName": "${storageaccount}",
          "storageAccountKey": "${storageaccountkey}"
        }
        SETTINGS
     }
    tags = {
        environment = "${var.environment}"
      }
}

And the file to mount Azure File Share

param(
    [Parameter(Mandatory=$true)]
    [string]$FileShare,

    [Parameter(Mandatory=$true)]
    [string]$StorageAccountAccessKey,
    
    [Parameter(Mandatory=$true)]
    [string]$StorageAccount
)

cmd.exe /C "cmdkey /add:`"${StorageAccount}.file.core.windows.net`" /user:`"localhost\${StorageAccount}`" /pass:`"${StorageAccountAccessKey}`""
# Mount the drive
net use "Z:" "\\${StorageAccount}.file.core.windows.net\${FileShare}" /persistent:yes

but I have errors such :

Connecting to local system...\r\n\r\n\r\nCouldn't install PSEXESVC service:\r\nThe handle is invalid.\r\nConnecting to local system...\r\n\r\n\r\nStarting PSEXESVC service on local system...\r\n\r\n\r\nCopying authentication key to...

I want to mount azure-fileshare for all users.

Does someone have any ideas?

0

There are 0 answers