Почему Move-AzResource не может переместить ресурсы с зависимостями в пределах одной группы ресурсов? - PullRequest
0 голосов
/ 31 марта 2020

Я пытаюсь написать сценарий powershell, который автоматизирует объединение всех ресурсов в одну группу ресурсов, но я получаю сообщения об ошибках, которые останавливают выполнение Move-AzResource.

$resources = Get-AzResource
#Skip already migrated resources:
$resources = $resources | Where-Object {$_.ResourceGroupName -ne "spMigrateResourceGroup"}

$groups = $resources | Group-Object ResourceGroupName
$groups = $groups.Name

$groups | ForEach-Object {
    $group = $_

    $groupResources = $resources | Where-Object ResourceGroupName -eq $group
    $groupResourceIds = $groupResources.ResourceId

    $response = Move-AzResource -DestinationResourceGroupName $resourceGroupTarget `
    -ResourceId $groupResourceIds -Force -Verbose -Debug

    Write-Host $response
}

Так как Move-AzResource ограничен для одновременного перемещения ресурсов в одной и той же группе ресурсов, я беру resourceId в пределах одной и той же группы ресурсов и инициирую Move-AzResource, но я сталкиваюсь с ошибками типа:

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

Status Code:
BadRequest

Headers:
Cache-Control                 : no-cache
Pragma                        : no-cache
x-ms-failure-cause            : gateway
x-ms-ratelimit-remaining-subscription-writes: 1199
x-ms-request-id               : e0f0f5e3-faaf-44ad-b3e4-61e51ad89a84
x-ms-correlation-request-id   : e0f0f5e3-faaf-44ad-b3e4-61e51ad89a84
x-ms-routing-request-id       : SOUTHCENTRALUS:20200331T165747Z:e0f0f5e3-faaf-44ad-b3e4-61e51ad89a84
Strict-Transport-Security     : max-age=31536000; includeSubDomains
X-Content-Type-Options        : nosniff
Date                          : Tue, 31 Mar 2020 16:57:46 GMT

Body:
{
  "error": {
    "code": "MultipleErrorsOccurred",
    "message": "Multiple error occurred: BadRequest,BadRequest,BadRequest,BadRequest,BadRequest,BadRequest,BadRequest,BadRequest,BadRequest,BadRequest,BadRequest,BadRequest,BadRequest,BadRequest,BadRequest. Please see details.",
    "details": [
      {
        "code": "ResourceNotTopLevel",
        "message": "Identifier '//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2S17W19/extensions/SqlIaasExtension' is not a top level resource."
      },
      {
        "code": "ResourceNotTopLevel",
        "message": "Identifier '//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2S17W19/extensions/joindomain' is not a top level resource."
      },
      {
        "code": "ResourceNotTopLevel",
        "message": "Identifier '//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDS02/extensions/SiteRecovery-Windows' is not a top level resource."
      },
      {
        "code": "ResourceNotTopLevel",
        "message": "Identifier '//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDS02/extensions/BGInfo' is not a top level resource."
      },
      {
        "code": "ResourceNotTopLevel",
        "message": "Identifier '//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDS01/extensions/SiteRecovery-Windows' is not a top level resource."
      },
      {
        "code": "ResourceNotTopLevel",
        "message": "Identifier '//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDS01/extensions/BGInfo' is not a top level resource."
      },
      {
        "code": "ResourceNotTopLevel",
        "message": "Identifier '//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDG02/extensions/SiteRecovery-Windows' is not a top level resource."
      },
      {
        "code": "ResourceNotTopLevel",
        "message": "Identifier '//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDG02/extensions/BGInfo' is not a top level resource."
      },
      {
        "code": "ResourceNotTopLevel",
        "message": "Identifier '//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDG01/extensions/SiteRecovery-Windows' is not a top level resource."
      },
      {
        "code": "ResourceNotTopLevel",
        "message": "Identifier '//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDG01/extensions/BGInfo' is not a top level resource."
      },
      {
        "code": "ResourceNotTopLevel",
        "message": "Identifier '//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2DFS01/extensions/SiteRecovery-Windows' is not a top level resource."
      },
      {
        "code": "ResourceNotTopLevel",
        "message": "Identifier '//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2DFS01/extensions/BGInfo' is not a top level resource."
      },
        "message": "Identifier '//resourceGroups/rg-spoc-ae2/providers/      },
      {                                                                                                                  Microsoft.Compute/virtualMachines/SPOCAE2BIS01/extensions/SiteRecovery-Windows' is not a top level resource."
        "code": "ResourceNotTopLevel",
        "message": "Identifier '//resourceGroups/RG-SPOC-AE2/providers/      },
      {                                                                                                                  Microsoft.Compute/virtualMachines/SPOCAE2BIS01/extensions/BGInfo' is not a top level resource."
        "code": "ResourceNotTopLevel",
        "message": "Identifier '//resourceGroups/rg-spoc-ae2/providers/      },
      {                                                                                                                  Microsoft.Compute/virtualMachines/SPOCAE2ADS01/extensions/Microsoft.Powershell.DSC' is not a top level resource."
        "code": "ResourceNotTopLevel",
        "message": "Identifier '//resourceGroups/RG-SPOC-AE2/providers/      },
      {
        "code": "ResourceNotTopLevel",
        "message": "Identifier '//resourceGroups/rg-spoc-ae2/providers/
      },
      {
        "code": "ResourceNotTopLevel",
        "message": "Identifier '//resourceGroups/RG-SPOC-AE2/providers/
      },
      {
        "code": "ResourceNotTopLevel",
        "message": "Identifier '//resourceGroups/RG-SPOC-AE2/providers/
      }
    ]
  }
}

Я считаю, что когда он говорит «ResourceNotTopLevel», он говорит, что это зависимость и должен перемещаться вместе с ресурсом верхнего уровня, который управляет им, как сервер базы данных с базами данных. Но я вполне уверен, что зависимости и иждивенцы упакованы в одной и той же группе ресурсов и поэтому предоставляются в команде Move-AzResource. Фактически, я могу инициировать ту же команду на портале Azure, используя функцию «Переместить» групп ресурсов, и она успешно перемещает каждый ресурс в группе в целевую группу ресурсов - что предлагает мне все необходимое для перемещения находится в группе ресурсов.

Так что я думаю, что мой вопрос состоит из двух частей: почему это происходит (особенно если это работает на портале) и почему Move-AzResource по крайней мере не продвигается вперед? переместить ресурсы это может? В документах предполагается, что команда делает все возможное, чтобы переместить то, что она может, но Move-AzResource, похоже, останавливается при попытке проверить некоторые ошибочные запросы. Вот ресурсы, отправленные с одной итерацией l oop:

Body:
{
  "targetResourceGroup": "//resourceGroups/spMigrateResourceGroup",
  "resources": [
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Storage/storageAccounts/stoae2arscache",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Storage/storageAccounts/frankcloudshellstorage",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.SqlVirtualMachine/SqlVirtualMachines/SPOCAE2S17W19",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/virtualNetworks/VNET-SPOC-AE2",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/publicIPAddresses/SQL-EXTERNAL",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/publicIPAddresses/SQL2014SP3-EXTERNAL",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/publicIPAddresses/PIP-VNG-VNET-SPOC-AE2",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/publicIPAddresses/PIP-SPOCAE2NST01-1",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/publicIPAddresses/PIP-RDG-SPOC-AE2",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/publicIPAddresses/PIP-EXTERNAL",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/publicIPAddresses/PIP-DFS",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/publicIPAddresses/PIP-ADS",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/networkSecurityGroups/NSG-SPOC-AE2",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/networkInterfaces/spocae2nst01155",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/networkInterfaces/NIC-SPOCAE2S17W19-01",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/networkInterfaces/NIC-SPOCAE2RDS02-1",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/networkInterfaces/NIC-SPOCAE2RDS01-1",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/networkInterfaces/NIC-SPOCAE2RDG02-1",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/networkInterfaces/NIC-SPOCAE2RDG01-1",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/networkInterfaces/NIC-SPOCAE2DFS01-1",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/networkInterfaces/NIC-SPOCAE2BIS02-1",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/networkInterfaces/NIC-SPOCAE2BIS01-1",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/networkInterfaces/NIC-SPOCAE2ADS01-1",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/localNetworkGateways/LNG-VNET-SPOC-AWU",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/loadBalancers/ILB-SPOCAFCAE2-SSRS",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/loadBalancers/ILB-SPOCAFCAE2-SQL",
    "//resourceGroups/rg-spoc-ae2/providers/Microsoft.DevTestLab/schedules/shutdown-computevm-SPOCAE2DFS01",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.DevTestLab/schedules/shutdown-computevm-SPOCAE2ADS01",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2S17W19/extensions/SqlIaasExtension",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2S17W19/extensions/joindomain",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2S17W19",
    "//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDS02/extensions/SiteRecovery-Windows",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDS02/extensions/BGInfo",
    "//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDS02",
    "//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDS01/extensions/SiteRecovery-Windows",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDS01/extensions/BGInfo",
    "//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDS01",
    "//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDG02/extensions/SiteRecovery-Windows",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDG02/extensions/BGInfo",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDG02",
    "//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDG01/extensions/SiteRecovery-Windows",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDG01/extensions/BGInfo",
    "//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDG01",
    "//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2DFS01/extensions/SiteRecovery-Windows",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2DFS01/extensions/BGInfo",
    "//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2DFS01",
    "//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2BIS01/extensions/SiteRecovery-Windows",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2BIS01/extensions/BGInfo",
    "//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2BIS01",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2ADS01/extensions/Microsoft.Powershell.DSC",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2ADS01",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SQL_TEMPDB_H",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SQL_OSDISK",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SQL_LOG_G",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SQL_DATA_F",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SQL2014SP3_TEMPDB_H",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SQL2014SP3_OSDISK",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SQL2014SP3_LOG_G",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SQL2014SP3_DATA_F",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SPOCAE2S17W19_TEMPDB_H",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SPOCAE2S17W19_OSDISK",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SPOCAE2S17W19_LOG_G",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SPOCAE2S17W19_DATA_F",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SPOCAE2RDS02_OSDISK.vhd",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SPOCAE2RDS01_OSDISK.vhd",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SPOCAE2RDG02_OSDISK.vhd",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SPOCAE2RDG01_OSDISK.vhd",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SPOCAE2NST01_OsDisk_1_1e0ef5ca87c34a0d9283d37b3c531910",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SPOCAE2DFS01_OSDISK.vhd",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SPOCAE2DFS01_DFS_DISK_1",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SPOCAE2BIS02_OSDISK.vhd",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SPOCAE2BIS01_OSDISK.vhd",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SPOCAE2ADS01_OSDISK.vhd",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/availabilitySets/AS-SPOC-SQL-AE2",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/availabilitySets/AS-SPOC-RDS-AE2",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/availabilitySets/AS-SPOC-RDG-AE2",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/availabilitySets/AS-SPOC-DFS-AE2",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/availabilitySets/AS-SPOC-BIS-AE2",
    "//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/availabilitySets/AS-SPOC-ADS-AE2"
  ]
}

Примечание: я вырезал подписки из предоставленных ошибок.

Обновление: Вот сообщение об ошибке, предшествующее расширенный журнал отладки:

Message        : MultipleErrorsOccurred : Multiple error occurred: BadRequest,BadRequest,BadRequest,BadRequest,BadRequest,BadRequest,BadRequest,BadRequest,BadRequest,BadRequest,BadRequest,BadRequest,BadRequest,BadRequest,BadRequest. Please see details.
StackTrace     :    at Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.ResourceManagerCmdletBase.HandleException(ExceptionDispatchInfo capturedException)
                    at Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.ResourceManagerCmdletBase.EndProcessing()
                    at System.Management.Automation.CommandProcessorBase.Complete()
Exception      : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Entities.ErrorResponses.ErrorResponseMessageException
InvocationInfo : {Move-AzResource}
Line           :     $response = Move-AzResource -DestinationResourceGroupName $resourceGroupTarget `

Position       : At ...\aggregator.ps1:82 char:17
                 + … $response = Move-AzResource -DestinationResourceGroupName $resourceGr …
                 +  

Ответы [ 2 ]

0 голосов
/ 02 апреля 2020

Оказывается, вы можете предотвратить это, выполнив:

$topResources = $resources | Where-Object { -not $_.ParentResource}

Обнаружено из this .

0 голосов
/ 31 марта 2020

Из ресурсов удалите все .../extensions/xxx ресурсы. то есть:

"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2S17W19/extensions/SqlIaasExtension",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2S17W19/extensions/joindomain",
"//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDS02/extensions/SiteRecovery-Windows",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDS02/extensions/BGInfo",
"//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDS01/extensions/SiteRecovery-Windows",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDS01/extensions/BGInfo",
"//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDG02/extensions/SiteRecovery-Windows",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDG02/extensions/BGInfo",
"//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDG01/extensions/SiteRecovery-Windows",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDG01/extensions/BGInfo",
"//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2DFS01/extensions/SiteRecovery-Windows",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2DFS01/extensions/BGInfo",
"//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2BIS01/extensions/SiteRecovery-Windows",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2BIS01/extensions/BGInfo",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2ADS01/extensions/Microsoft.Powershell.DSC",

Если мы возьмем эту машину (SPOCAE2S17W19) и связанные ресурсы в качестве примера:

"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2S17W19/extensions/SqlIaasExtension",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2S17W19/extensions/joindomain",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2S17W19",

Группа «верхнего уровня» в этом случае:

.../virtualMachines/SPOCAE2S17W19

Другие ресурсы под ним:

.../virtualMachines/SPOCAE2S17W19/extensions/SqlIaasExtension
.../virtualMachines/SPOCAE2S17W19/extensions/joindomain

Не являются "группами верхнего уровня".

Эти расширения будут автоматически перемещаться с основной группой "верхнего уровня" например, .../virtualMachines/SPOCAE2S17W19.

...