diff --git a/avm/utilities/pipelines/e2eValidation/resourceRemoval/helper/Get-DeploymentTargetResourceList.ps1 b/avm/utilities/pipelines/e2eValidation/resourceRemoval/helper/Get-DeploymentTargetResourceList.ps1 index 7c658659e0..d60a8ad875 100644 --- a/avm/utilities/pipelines/e2eValidation/resourceRemoval/helper/Get-DeploymentTargetResourceList.ps1 +++ b/avm/utilities/pipelines/e2eValidation/resourceRemoval/helper/Get-DeploymentTargetResourceList.ps1 @@ -188,7 +188,8 @@ function Get-DeploymentTargetResourceList { [string] $ManagementGroupId, [Parameter(Mandatory = $true)] - [string] $Name, + [Alias('Name', 'Names', 'DeploymentName')] + [string[]] $DeploymentNames, [Parameter(Mandatory = $true)] [ValidateSet( @@ -207,31 +208,57 @@ function Get-DeploymentTargetResourceList { ) $searchRetryCount = 1 - do { - $innerInputObject = @{ - Name = $name - Scope = $scope - ErrorAction = 'SilentlyContinue' + $resourcesToRemove = @() + $deploymentNameObjects = $DeploymentNames | ForEach-Object { + @{ + Name = $_ + Resolved = $false } - if (-not [String]::IsNullOrEmpty($resourceGroupName)) { - $innerInputObject['resourceGroupName'] = $resourceGroupName - } - if (-not [String]::IsNullOrEmpty($ManagementGroupId)) { - $innerInputObject['ManagementGroupId'] = $ManagementGroupId + } + + do { + foreach ($deploymentNameObject in $deploymentNameObjects) { + + if ($deploymentNameObject.Resolved) { + # Skip further invocations for this deployment name if deployment was already found + continue + } + + $innerInputObject = @{ + Name = $deploymentNameObject.Name + Scope = $scope + ErrorAction = 'SilentlyContinue' + } + if (-not [String]::IsNullOrEmpty($resourceGroupName)) { + $innerInputObject['resourceGroupName'] = $resourceGroupName + } + if (-not [String]::IsNullOrEmpty($ManagementGroupId)) { + $innerInputObject['ManagementGroupId'] = $ManagementGroupId + } + + [array]$targetResources = Get-DeploymentTargetResourceListInner @innerInputObject + if ($targetResources.Count -gt 0) { + Write-Verbose ('Found & resolved deployment [{0}]' -f $deploymentNameObject.Name) -Verbose + $deploymentNameObject.Resolved = $true + $resourcesToRemove += $targetResources + } } - [array]$targetResources = Get-DeploymentTargetResourceListInner @innerInputObject - if ($targetResources) { + + # Break check + if ($deploymentNameObjects.Resolved -notcontains $false) { break } - Write-Verbose ('No deployment found by name [{0}] in scope [{1}]. Retrying in [{2}] seconds [{3}/{4}]' -f $name, $scope, $searchRetryInterval, $searchRetryCount, $searchRetryLimit) -Verbose + + $remainingDeploymentNames = ($deploymentNameObjects | Where-Object { -not $_.Resolved }).Name + Write-Verbose ('No deployment found by name(s) [{0}] in scope [{1}]. Retrying in [{2}] seconds [{3}/{4}]' -f ($remainingDeploymentNames -join ', '), $scope, $searchRetryInterval, $searchRetryCount, $searchRetryLimit) -Verbose Start-Sleep $searchRetryInterval $searchRetryCount++ } while ($searchRetryCount -le $searchRetryLimit) - if (-not $targetResources) { - Write-Warning "No deployment target resources found for [$name]" + if (-not $resourcesToRemove) { + Write-Warning ('No deployment target resources found for [{0}]' -f ($DeploymentNames -join ', ')) return @() } - return $targetResources + return $resourcesToRemove } diff --git a/avm/utilities/pipelines/e2eValidation/resourceRemoval/helper/Remove-Deployment.ps1 b/avm/utilities/pipelines/e2eValidation/resourceRemoval/helper/Remove-Deployment.ps1 index 00a0d50676..d64a963e1c 100644 --- a/avm/utilities/pipelines/e2eValidation/resourceRemoval/helper/Remove-Deployment.ps1 +++ b/avm/utilities/pipelines/e2eValidation/resourceRemoval/helper/Remove-Deployment.ps1 @@ -90,20 +90,17 @@ function Remove-Deployment { # Fetch deployments # ================= - - foreach ($deploymentName in $DeploymentNames) { - $deploymentsInputObject = @{ - Name = $deploymentName - Scope = $deploymentScope - } - if (-not [String]::IsNullOrEmpty($ResourceGroupName)) { - $deploymentsInputObject['resourceGroupName'] = $ResourceGroupName - } - if (-not [String]::IsNullOrEmpty($ManagementGroupId)) { - $deploymentsInputObject['ManagementGroupId'] = $ManagementGroupId - } - $deployedTargetResources += Get-DeploymentTargetResourceList @deploymentsInputObject + $deploymentsInputObject = @{ + DeploymentNames = $DeploymentNames + Scope = $deploymentScope + } + if (-not [String]::IsNullOrEmpty($ResourceGroupName)) { + $deploymentsInputObject['resourceGroupName'] = $ResourceGroupName + } + if (-not [String]::IsNullOrEmpty($ManagementGroupId)) { + $deploymentsInputObject['ManagementGroupId'] = $ManagementGroupId } + $deployedTargetResources += Get-DeploymentTargetResourceList @deploymentsInputObject if ($deployedTargetResources.Count -eq 0) { throw 'No deployment target resources found.'