Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Jefajers authored Feb 24, 2024
1 parent f33a738 commit ea833ad
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/internal/functions/Remove-AzOpsDeployment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@
# Initialize array to store items that need retry
$retry = @()
$removalJobChanges = Set-AzOpsRemoveOrder -DeletionList $removalJob.results.Changes -Index { (New-AzOpsScope -Scope $_.FullyQualifiedResourceId -WhatIf:$false).Resource }
$allResults = @()
foreach ($change in $removalJobChanges) {
$resource = $null
# Check if the resource exists
Expand All @@ -344,9 +345,9 @@
}
if ($resource) {
$results = 'What if successful:{1}Performing the operation:{1}Deletion of target resource {0}.' -f $change.FullyQualifiedResourceId, [environment]::NewLine
$allResults += $results
Write-AzOpsMessage -LogLevel Verbose -LogString 'Set-AzOpsWhatIfOutput.WhatIfResults' -LogStringValues $results
Write-AzOpsMessage -LogLevel InternalComment -LogString 'Set-AzOpsWhatIfOutput.WhatIfFile'
Set-AzOpsWhatIfOutput -FilePath $TemplateFilePath -ParameterFilePath $TemplateParameterFilePath -Results $results -RemoveAzOpsFlag $true
# Check if the removal should be performed
if ($PSCmdlet.ShouldProcess("Remove $($change.FullyQualifiedResourceId)?")) {
$removeAction = Remove-AzResourceRaw -FullyQualifiedResourceId $change.FullyQualifiedResourceId -ScopeObject $ScopeObject -TemplateFilePath $TemplateFilePath -TemplateParameterFilePath $TemplateParameterFilePath
Expand All @@ -363,10 +364,12 @@
# Log warning if resource not found
Write-AzOpsMessage -LogLevel Warning -LogString 'Remove-AzOpsDeployment.ResourceNotFound' -LogStringValues $scopeObject.resource, $change.FullyQualifiedResourceId
$results = 'What if operation failed:{1}Deletion of target resource {0}.{1}Resource could not be found' -f $change.FullyQualifiedResourceId, [environment]::NewLine
Set-AzOpsWhatIfOutput -FilePath $TemplateFilePath -ParameterFilePath $TemplateParameterFilePath -Results $results -RemoveAzOpsFlag $true
$allResults += $results
}

}
# Log WhatIf Output once for all resources in template
Set-AzOpsWhatIfOutput -FilePath $TemplateFilePath -ParameterFilePath $TemplateParameterFilePath -Results $allResults -RemoveAzOpsFlag $true
if ($retry.Count -gt 0) {
# Retry failed removals recursively
Write-AzOpsMessage -LogLevel InternalComment -LogString 'Remove-AzOpsDeployment.Resource.RetryCount' -LogStringValues $retry.Count
Expand Down

0 comments on commit ea833ad

Please sign in to comment.