Skip to content

StorageAccountLocationMismatch because of TryToChooseExistingStandardStorageAccount()  #5189

@axelgMS

Description

@axelgMS

Cmdlet(s)

New-AzureRmVM -ResourceGroupName $rg -Location $OriginalVM.Location -VM $NewVM -DisableBginfoExtension -debug -verbose

PowerShell Version

Instructions: to get PowerShell version, type $PSVersionTable and look for the value associated with PSVersion

Version : 5.1.1

Module Version

OS Version

Instructions: to get OS version, type $PSversionTable and look for value associated with BuildVersion

Windows 10 Pro RS3

Description

When creating a new Azure RM VM without specifying the Boot Diagnostics Storage Account, the first Storage Account in the RG will be chosen, no matter of its location.

Bug is in TryToChooseExistingStandardStorageAccount() which returns the first SA it finds in the RG - without checking if it's the same location as the VM being created.

private StorageAccount TryToChooseExistingStandardStorageAccount(StorageManagementClient client)
        {
            var storageAccountList = client.StorageAccounts.ListByResourceGroup(this.ResourceGroupName);
            if (storageAccountList == null || storageAccountList.Count() == 0)
            {
                storageAccountList = client.StorageAccounts.List().Where(e => e.Location.Canonicalize().Equals(this.Location.Canonicalize()));
                if (storageAccountList == null || storageAccountList.Count() == 0)
                {
                    return null;
                }
            }
            try
            {
                **return storageAccountList.First(**
                e => e.Sku() != null
                    && !e.SkuName().ToLowerInvariant().Contains("premium"));
            }
            catch (InvalidOperationException e)
            {
                WriteWarning(string.Format(
                            Properties.Resources.ErrorDuringChoosingStandardStorageAccount, e.Message));
                return null;
            }
        }

Debug Output

Instructions: to get Debug Output, set $DebugPreference="Continue" and then execute the cmdlet or script causing the issue

DEBUG: ============================ HTTP REQUEST ============================
HTTP Method:
GET
Absolute Uri:
https://management.azure.com/subscriptions/6eb19024-265b-4bce-8dd6-394e287cbc1a/resourceGroups/RG55196504/providers/Microsoft.Storage/storageAccounts?api-version=2015-06-15
Headers:
x-ms-client-request-id : 5890fc05-100c-4080-af0f-077a7e6e6b75
accept-language : en-US
Body:
DEBUG: ============================ HTTP RESPONSE ============================
Status Code:
OK
Headers:
Pragma : no-cache
x-ms-request-id : 92fb7cb1-4f73-47e9-950d-6186deb9b2f6
Strict-Transport-Security : max-age=31536000; includeSubDomains
Cache-Control : no-cache
Server : Microsoft-Azure-Storage-Resource-Provider/1.0,Microsoft-HTTPAPI/2.0
x-ms-ratelimit-remaining-subscription-reads: 14965
x-ms-correlation-request-id : 6c9b5a26-967c-4266-a441-4d5f6dbf4a8e
x-ms-routing-request-id : UKSOUTH:20171227T095511Z:6c9b5a26-967c-4266-a441-4d5f6dbf4a8e
Date : Wed, 27 Dec 2017 09:55:10 GMT

Body:
{
"value": [
{
"id": "/subscriptions/6eb19024-265b-4bce-8dd6-394e287cbc1a/resourceGroups/RG55196504/providers/Microsoft.Storage/storageAccounts/axelgsa55196504north",
"name": "axelgsa55196504north",
"type": "Microsoft.Storage/storageAccounts",
"location": "northeurope",
"properties": {
"accountType": "Standard_LRS",
"provisioningState": "Succeeded",
"creationTime": "2017-12-27T09:46:39.858315Z",
"primaryEndpoints": {
"blob": "https://axelgsa55196504north.blob.core.windows.net/",
"queue": "https://axelgsa55196504north.queue.core.windows.net/",
"table": "https://axelgsa55196504north.table.core.windows.net/",
"file": "https://axelgsa55196504north.file.core.windows.net/"
},
"primaryLocation": "northeurope",
"statusOfPrimary": "available"
}
}
]
}

WARNING: Since the VM is created using premium storage, existing standard storage account, axelgsa55196504north, is used for boot diagnostics.

DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
PUT

Absolute Uri:
https://management.azure.com/subscriptions/6eb19024-265b-4bce-8dd6-394e287cbc1a/resourceGroups/RG55196504/providers/Microsoft.Compute/virtualMachines/VM55196504-2?api-version=2017-12-01

Headers:
x-ms-client-request-id : 2248c1e4-c177-45d5-8dd4-abf0a180e735
accept-language : en-US

Body:
{
"properties": {
"hardwareProfile": {
"vmSize": "Standard_A1"
},
"storageProfile": {
"osDisk": {
"osType": "Windows",
"createOption": "Attach",
"managedDisk": {
"id": "/subscriptions/6eb19024-265b-4bce-8dd6-394e287cbc1a/resourceGroups/RG55196504/providers/Microsoft.Compute/disks/VM55196504-2_OsDisk_1_39a41afd4e9d4d72926df1dbdf9c59c9"
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/6eb19024-265b-4bce-8dd6-394e287cbc1a/resourceGroups/RG55196504/providers/Microsoft.Network/networkInterfaces/vm55196504-2962"
}
]
},
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": true,
"storageUri": "https://axelgsa55196504north.blob.core.windows.net/"
}
},
"availabilitySet": {
"id": "/subscriptions/6eb19024-265b-4bce-8dd6-394e287cbc1a/resourceGroups/RG55196504/providers/Microsoft.Compute/availabilitySets/AVset55196504"
}
},
"location": "westeurope"
}

DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
GET

Absolute Uri:
https://management.azure.com/subscriptions/6eb19024-265b-4bce-8dd6-394e287cbc1a/providers/Microsoft.Compute/locations/westeurope/operations/4866d5b8-b4ac-4255-ade7-411ea8cd5f89?api-version=2017-12-01

Headers:

Body:

DEBUG: ============================ HTTP RESPONSE ============================

Status Code:
OK

Headers:
Pragma : no-cache
x-ms-ratelimit-remaining-resource: Microsoft.Compute/GetOperation3Min;11975,Microsoft.Compute/GetOperation30Min;23900
Strict-Transport-Security : max-age=31536000; includeSubDomains
x-ms-served-by : 5a24a676-2428-4a0a-9594-6c701c41ee05_131576743378351509
x-ms-request-id : d43c7afe-abec-4b0a-a522-16738eb7adc5
Cache-Control : no-cache
Server : Microsoft-HTTPAPI/2.0,Microsoft-HTTPAPI/2.0
x-ms-ratelimit-remaining-subscription-reads: 14961
x-ms-correlation-request-id : 4e6d2356-9052-48e9-a113-77255d1cd02f
x-ms-routing-request-id : UKSOUTH:20171227T095548Z:4e6d2356-9052-48e9-a113-77255d1cd02f
Date : Wed, 27 Dec 2017 09:55:47 GMT

Body:
{
"startTime": "2017-12-27T10:55:19.0203344+01:00",
"endTime": "2017-12-27T10:55:28.61418+01:00",
"status": "Failed",
"error": {
"code": "StorageAccountLocationMismatch",
"message": "StorageAccount 'axelgsa55196504north' associated with VM 'VM55196504-2' for boot diagnostics encountered an error. Please look at the error code for more information about the error."
},
"name": "4866d5b8-b4ac-4255-ade7-411ea8cd5f89"
}

DEBUG: AzureQoSEvent: CommandName - New-AzureRmVM; IsSuccess - True; Duration - 00:00:39.2485621; Exception - ;
DEBUG: Finish sending metric.
DEBUG: 10:55:47 AM - NewAzureVMCommand end processing.
DEBUG: 10:55:47 AM - NewAzureVMCommand end processing.
New-AzureRmVM : Long running operation failed with status 'Failed'. Additional Info:'StorageAccount 'axelgsa55196504north' associated with VM 'VM55196504-2' for boot diagnostics encountered an error. Please look at the error code for more information about the error.'
ErrorCode: StorageAccountLocationMismatch
ErrorMessage: StorageAccount 'axelgsa55196504north' associated with VM 'VM55196504-2' for boot diagnostics encountered an error. Please look at the error code for more information about the error.
StartTime: 27-Dec-17 10:55:19 AM
EndTime: 27-Dec-17 10:55:28 AM
OperationID: 4866d5b8-b4ac-4255-ade7-411ea8cd5f89
Status: Failed
At line:1 char:5

  • New-AzureRmVM -ResourceGroupName $rg -Location $OriginalVM.Locati ...
    
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : CloseError: (:) [New-AzureRmVM], ComputeCloudException
    • FullyQualifiedErrorId : Microsoft.Azure.Commands.Compute.NewAzureVMCommand

DEBUG: AzureQoSEvent: CommandName - New-AzureRmVM; IsSuccess - False; Duration - 00:00:39.2485621; Exception - Microsoft.Azure.Commands.Compute.Common.ComputeCloudException: Long running operation failed with status 'Failed'. Additional Info:'StorageAccount 'axelgsa55196504north' associated with VM 'VM55196504-2' for boot
diagnostics encountered an error. Please look at the error code for more information about the error.'
ErrorCode: StorageAccountLocationMismatch
ErrorMessage: StorageAccount 'axelgsa55196504north' associated with VM 'VM55196504-2' for boot diagnostics encountered an error. Please look at the error code for more information about the error.
StartTime: 27-Dec-17 10:55:19 AM
EndTime: 27-Dec-17 10:55:28 AM
OperationID: 4866d5b8-b4ac-4255-ade7-411ea8cd5f89
Status: Failed ---> Microsoft.Rest.Azure.CloudException: Long running operation failed with status 'Failed'. Additional Info:'StorageAccount 'axelgsa55196504north' associated with VM 'VM55196504-2' for boot diagnostics encountered an error. Please look at the error code for more information about the error.'
at Microsoft.Rest.Azure.AzureClientExtensions.d__12.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Rest.Azure.AzureClientExtensions.<GetLongRunningOperationResultAsync>d__01.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Rest.Azure.AzureClientExtensions.d__4`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Management.Compute.VirtualMachinesOperations.d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Commands.Compute.NewAzureVMCommand.b__88_0()
at Microsoft.Azure.Commands.Compute.ComputeClientBaseCmdlet.ExecuteClientAction(Action action)
--- End of inner exception stack trace ---
at Microsoft.Azure.Commands.Compute.ComputeClientBaseCmdlet.ExecuteClientAction(Action action)
at Microsoft.Azure.Commands.Compute.NewAzureVMCommand.DefaultExecuteCmdlet()
at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord();
DEBUG: Finish sending metric.
DEBUG: 10:55:59 AM - NewAzureVMCommand end processing.
DEBUG: 10:55:59 AM - NewAzureVMCommand end processing.

Script/Steps for Reproduction

Create a VM in a given location - say West Europe
Once it's done - delete the associated Boot Diagnostics Storage Account - and create a new SA in the same RG, but in another region (eg. North Europe)

then deploy a new VM based on the existing one

#Remove the original VM
Remove-AzureRmVM -ResourceGroupName $rg -Name $vmName

#Create new availability set if it does not exist
#$availSet = Get-AzureRmAvailabilitySet -ResourceGroupName $rg -Name $newAvailSetName -ErrorAction Ignore
#if (-Not $availSet) {
#$availset = New-AzureRmAvailabilitySet -ResourceGroupName $rg -Name $newAvailSetName -Location $OriginalVM.Location
#}

$availSet = Get-AzureRmAvailabilitySet -ResourceGroupName $rg -Name $newAvailSetName

#Create the basic configuration for the replacement VM
#$newVM = New-AzureRmVMConfig -VMName $OriginalVM.Name -VMSize $OriginalVM.HardwareProfile.VmSize -AvailabilitySetId $availSet.Id
$newVM = New-AzureRmVMConfig -VMName $OriginalVM.Name -VMSize $OriginalVM.HardwareProfile.VmSize -AvailabilitySetId $availSet.Id
#Set-AzureRmVMOSDisk -VM $NewVM -ManagedDiskId $OriginalVM.StorageProfile.OsDisk.ManagedDisk.Id  -Name $OriginalVM.Name -CreateOption Attach -Windows
Set-AzureRmVMOSDisk -VM $NewVM -ManagedDiskId $OriginalVM.StorageProfile.OsDisk.ManagedDisk.Id  -CreateOption Attach -Windows
#Set-AzureRmVMBootDiagnostics -VM $newVM -Enable -ResourceGroupName "course2" -StorageAccountName "course25109"

#Add Data Disks

foreach ($disk in $OriginalVM.StorageProfile.DataDisks ) {

#Add-AzureRmVMDataDisk -VM $newVM -Name $disk.Name -ManagedDiskId $disk.Vhd.Uri -Caching $disk.Caching -Lun $disk.Lun -CreateOption Attach -DiskSizeInGB $disk.DiskSizeGB

}

#Add NIC(s)
foreach ($nic in $OriginalVM.NetworkProfile.NetworkInterfaces) {
    Add-AzureRmVMNetworkInterface -VM $NewVM -Id $nic.Id
}

#Create the VM
New-AzureRmVM -ResourceGroupName $rg -Location $OriginalVM.Location -VM $NewVM -DisableBginfoExtension -debug -verbose

that will fail with:

New-AzureRmVM : Long running operation failed with status 'Failed'. Additional Info:'StorageAccount 'axelgsa55196504north' associated with VM 'VM55196504-2' for boot diagnostics encountered an error. Please look at the error code for more information about the error.'
ErrorCode: StorageAccountLocationMismatch
ErrorMessage: StorageAccount 'axelgsa55196504north' associated with VM 'VM55196504-2' for boot diagnostics encountered an error. Please look at the error code for more information about the error.
StartTime: 27-Dec-17 10:55:19 AM
EndTime: 27-Dec-17 10:55:28 AM
OperationID: 4866d5b8-b4ac-4255-ade7-411ea8cd5f89
Status: Failed
At line:1 char:5

  • New-AzureRmVM -ResourceGroupName $rg -Location $OriginalVM.Locati ...
    
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : CloseError: (:) [New-AzureRmVM], ComputeCloudException
    • FullyQualifiedErrorId : Microsoft.Azure.Commands.Compute.NewAzureVMCommand

Metadata

Metadata

Assignees

No one assigned

    Labels

    Compute - VMService AttentionThis issue is responsible by Azure service team.bugThis issue requires a change to an existing behavior in the product in order to be resolved.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions