Skip to content

Commit

Permalink
fix: Added retry to post-removal logic (Azure#2705)
Browse files Browse the repository at this point in the history
## Description

I noticed a few times now that especially the KeyVault post-removal
command sometimes fails with a generic error (sending a request). For
the implementation today, that unfortunately means that the removal
script throws an exception and stops - leaving a lot of resources still
in Azure.
Even more unfortunate is the fact that the purge actually worked in
those cases and I can only assume that the cmdlet has an internal issue
checking the latest state of the purge.

To help the matter in a generic way (that it, address the same for other
post-removal cases), I added a retry logic similar to our default
resource removal. All our post-removal script blocks are written in a
way that they can cope with a retry as they always check first if they
can find the soft-deleted resource before doing anything.

Example
[run](https://github.com/Azure/bicep-registry-modules/actions/runs/9886800221/job/27331338137#step:4:885)
```
  VERBOSE: [-] Removing resource [dep-***-law-kvvwaf] of type [Microsoft.OperationalInsights/workspaces]
  VERBOSE: [*] Purging resource [dep-***-law-kvvwaf] of type [Microsoft.OperationalInsights/workspaces]
  VERBOSE: [-] Removing resource [***kvvwaf002] of type [Microsoft.KeyVault/vaults]
  VERBOSE: [*] Purging resource [***kvvwaf002] of type [Microsoft.KeyVault/vaults]
  WARNING: [!] Post-removal operation failed. Reason: [An error occurred while sending the request.]. Retry [1/3]
  VERBOSE: [-] Removing resource [dep-***-msi-kvvwaf] of type [Microsoft.ManagedIdentity/userAssignedIdentities]
```

## Pipeline Reference

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

| Pipeline |
| -------- |
|
[![avm.res.key-vault.vault](https://github.com/Azure/bicep-registry-modules/actions/workflows/avm.res.key-vault.vault.yml/badge.svg?branch=users%2Falsehr%2FkvltPurgeRobustness&event=workflow_dispatch)](https://github.com/Azure/bicep-registry-modules/actions/workflows/avm.res.key-vault.vault.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 Jul 18, 2024
1 parent 491aa59 commit 3f2ddd8
Showing 1 changed file with 151 additions and 136 deletions.
Loading

0 comments on commit 3f2ddd8

Please sign in to comment.