Skip to content

Ensure /test-destroy-env also destroys management RG when core RG is absent#4925

Open
Copilot wants to merge 3 commits into
mainfrom
copilot/test-destroy-env-fix
Open

Ensure /test-destroy-env also destroys management RG when core RG is absent#4925
Copilot wants to merge 3 commits into
mainfrom
copilot/test-destroy-env-fix

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jun 6, 2026

What is being addressed

/test-destroy-env exited early if the core RG (rg-tre<ref>) was already gone, so prefixed groups like rg-tre<ref>-mgmt were left behind. This left management-state resources undeleted and could preserve stale Terraform state locks.

How is this addressed

  • Destroy scope resolution

    • The script now resolves all resource groups with the core prefix first and exits only when none exist.
    • This ensures management RG cleanup still runs even if the core RG no longer exists.
  • Core-only cleanup gating

    • Core-specific pre-delete operations (locks/diagnostics/keyvault/log analytics linked storage) now run only when the core RG is present.
    • When absent, the script logs a targeted skip message and continues with group deletion.
  • Deletion path reuse

    • Reuses the precomputed RG match list for final deletion to keep selection and execution aligned.
matching_resource_groups=$(az group list --query "[?starts_with(name, '${core_tre_rg}')].[name]" -o tsv | sort -r)
if [[ -z "${matching_resource_groups}" ]]; then
  echo "No resource groups found with prefix ${core_tre_rg} - skipping destroy"
  exit 0
fi
  • Follow-ups
    • No additional follow-up work identified.
    • No documentation, changelog, or template version updates were required for this change.

Copilot AI changed the title [WIP] Fix /test-destroy-env cleanup for mgt resource groups Ensure /test-destroy-env also destroys management RG when core RG is absent Jun 6, 2026
Copilot AI requested a review from rudolphjacksonm June 6, 2026 17:40
@rudolphjacksonm
Copy link
Copy Markdown
Collaborator

/test

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 6, 2026

🤖 pr-bot 🤖

⚠️ When using /test on external PRs, the SHA of the checked commit must be specified

(in response to this comment from @rudolphjacksonm)

@rudolphjacksonm
Copy link
Copy Markdown
Collaborator

/test 2a69a8e

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 6, 2026

🤖 pr-bot 🤖

🏃 Running tests: https://github.com/microsoft/AzureTRE/actions/runs/27072873570 (with refid b80dde45)

(in response to this comment from @rudolphjacksonm)

@rudolphjacksonm
Copy link
Copy Markdown
Collaborator

/test-destroy-env

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 7, 2026

Destroying branch test environment (RG: rg-trea6436f6c)... (run: https://github.com/microsoft/AzureTRE/actions/runs/27084269577)

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 7, 2026

Destroying PR test environment (RG: rg-treb80dde45)... (run: https://github.com/microsoft/AzureTRE/actions/runs/27084269577)

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 7, 2026

Branch test environment destroy complete (RG: rg-trea6436f6c)

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 7, 2026

PR test environment destroy complete (RG: rg-treb80dde45)

@rudolphjacksonm rudolphjacksonm requested a review from marrobi June 7, 2026 07:05
@rudolphjacksonm rudolphjacksonm marked this pull request as ready for review June 7, 2026 07:05
@rudolphjacksonm rudolphjacksonm requested a review from a team as a code owner June 7, 2026 07:05
Copilot AI review requested due to automatic review settings June 7, 2026 07:05
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the /test-destroy-env deletion script to correctly clean up all TRE-related resource groups (including -mgmt) even when the core resource group (rg-tre<ref>) has already been deleted, preventing leftover management resources/state.

Changes:

  • Resolve and cache all resource groups matching the core prefix up front; only exit early when none exist.
  • Gate “core RG only” cleanup steps (locks, diagnostics, key vault handling, log analytics linked storage) on the core RG actually existing.
  • Reuse the cached matching RG list for the final per-RG purge/delete loop to keep selection consistent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

/test-destroy-env does not clean up mgt resource groups

3 participants