Skip to content

Commit

Permalink
fix: Added addtional exception handling for removal (#2312)
Browse files Browse the repository at this point in the history
## Description

- Added case handling where a removal would be attempted on an already
removed resource. Should not be moved back for retry, but skipped.
- Handles a failed pipeline run/removal like
[this](https://github.com/Azure/bicep-registry-modules/actions/runs/9464572065/job/26072384019#step:4:868)

## Pipeline Reference

<!-- Insert your Pipeline Status Badge below -->

| Pipeline |
| -------- |
|
[![avm.res.storage.storage-account](https://github.com/Azure/bicep-registry-modules/actions/workflows/avm.res.storage.storage-account.yml/badge.svg?branch=users%2Falsehr%2FresourceNotFoundRemovalUpdate&event=workflow_dispatch)](https://github.com/Azure/bicep-registry-modules/actions/workflows/avm.res.storage.storage-account.yml)
|

## Type of Change

<!-- Use the checkboxes [x] on the options that are relevant. -->

- [x] Update to CI Environment or utilities (Non-module affecting
changes)
- [ ] Azure Verified Module updates:
- [ ] Bugfix containing backwards-compatible bug fixes, and I have NOT
bumped the MAJOR or MINOR version in `version.json`:
- [ ] Someone has opened a bug report issue, and I have included "Closes
#{bug_report_issue_number}" in the PR description.
- [ ] The bug was found by the module author, and no one has opened an
issue to report it yet.
- [ ] Feature update backwards compatible feature updates, and I have
bumped the MINOR version in `version.json`.
- [ ] Breaking changes and I have bumped the MAJOR version in
`version.json`.
  - [ ] Update to documentation
  • Loading branch information
AlexanderSehr authored Jun 12, 2024
1 parent 5bd7598 commit 20b86d0
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,15 @@ function Remove-ResourceListInner {
[array]$processedResources += $resource.resourceId
[array]$resourcesToRetry = $resourcesToRetry | Where-Object { $_.resourceId -notmatch $resource.resourceId }
} catch {
Write-Warning ('[!] Removal moved back for retry. Reason: [{0}]' -f $_.Exception.Message)
[array]$resourcesToRetry += $resource
if ($_.Exception.HttpStatus -in @(404, 'NotFound')) {
# Skipping because resource/parent is missing. This 'exception handling' can be required in case the parent resource removal ran into an issue, but was completed regardless
Write-Verbose ('[/] Skipping resource [{0}] of type [{1}]. Reason: It or its parent cannot be found.' -f $resourceName, $resource.type) -Verbose
[array]$processedResources += $resource.resourceId
[array]$resourcesToRetry = $resourcesToRetry | Where-Object { $_.resourceId -notmatch $resource.resourceId }
} else {
Write-Warning ('[!] Removal moved back for retry. Reason: [{0}]' -f $_.Exception.Message)
[array]$resourcesToRetry += $resource
}
}
}

Expand Down

0 comments on commit 20b86d0

Please sign in to comment.