Skip to content

Implement Remove-AzBootstrapEnvironment function with comprehensive cleanup and interactive mode#48

Draft
kewalaka with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-16
Draft

Implement Remove-AzBootstrapEnvironment function with comprehensive cleanup and interactive mode#48
kewalaka with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-16

Conversation

Copilot AI commented May 31, 2025

Copy link
Copy Markdown

This PR implements the Remove-AzBootstrapEnvironment function to provide complete environment removal capabilities, addressing the functionality that was previously removed when focusing on Bicep-based resource creation.

Changes

New Functions Added

  • Remove-AzBootstrapEnvironment (public) - Main orchestrator function with both parameter-based and interactive modes
  • Get-AzBootstrapEnvironmentConfig (private) - Reads environment configuration from .azbootstrap.jsonc tracking file
  • Remove-GitHubEnvironment (private) - Deletes GitHub environments via GitHub API
  • Remove-AzDeploymentStack (private) - Removes Azure deployment stacks with automatic resource cleanup
  • Remove-AzBootstrapConfig (private) - Updates configuration file to remove environment entries

Key Features

Interactive Mode: When no environment name is provided, the function displays available environments from the tracking file and allows selection by number or name:

# Interactive mode - shows list of environments to choose from
Remove-AzBootstrapEnvironment

Parameter-based Mode: Direct specification of environment and repository details:

# Remove specific environment
Remove-AzBootstrapEnvironment -EnvironmentName "test" -Force

# With explicit repository details
Remove-AzBootstrapEnvironment -EnvironmentName "prod" -GitHubOwner "myorg" -GitHubRepo "myrepo" -Force

Comprehensive Cleanup: The function removes:

  • Azure deployment stack (automatically deletes resource group, managed identities, role assignments, etc.)
  • GitHub environments (both plan and apply environments)
  • Environment entry from .azbootstrap.jsonc tracking file

Robust Error Handling: Continues cleanup operations even if individual steps fail, ensuring maximum resource cleanup with appropriate warnings.

Implementation Details

  • Leverages the .azbootstrap.jsonc tracking file introduced in Add .azbootstrap.jsonc tracking file to monitor resources under az-bootstrap control #32 to identify managed resources
  • Uses Azure deployment stacks for clean resource removal (consistent with creation pattern)
  • Follows existing code patterns from Add-AzBootstrapEnvironment for consistency
  • Implements idempotent operations that handle missing resources gracefully
  • Supports WhatIf and Confirm parameters for safe operation

Testing

Added comprehensive test coverage with 13 new tests:

  • Test-GetAzBootstrapEnvironmentConfig.Tests.ps1 - Configuration file reading
  • Test-RemoveGitHubEnvironment.Tests.ps1 - GitHub environment deletion
  • Test-RemoveAzBootstrapConfig.Tests.ps1 - Configuration file updates
  • Test-RemoveAzBootstrapEnvironment.Tests.ps1 - Main function integration

All existing tests continue to pass, ensuring no regressions.

Documentation

Updated README.md with:

  • Usage examples for environment removal
  • Detailed explanation of cleanup operations
  • Interactive mode documentation

Usage Examples

# Interactive mode
Remove-AzBootstrapEnvironment

# Remove specific environment with confirmation
Remove-AzBootstrapEnvironment -EnvironmentName "test"

# Force removal without prompts (for automation)
Remove-AzBootstrapEnvironment -EnvironmentName "staging" -Force

The implementation provides a clean, user-friendly way to remove environments while ensuring thorough cleanup of both Azure and GitHub resources.

Fixes #16.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits May 31, 2025 03:16
…prehensive tests

Co-authored-by: kewalaka <3146590+kewalaka@users.noreply.github.com>
Co-authored-by: kewalaka <3146590+kewalaka@users.noreply.github.com>
Copilot AI changed the title [WIP] issue: Remove-AzBootstrapEnvironment needs re-instating Implement Remove-AzBootstrapEnvironment function with comprehensive cleanup and interactive mode May 31, 2025
Copilot AI requested a review from kewalaka May 31, 2025 03:19
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.

issue: Remove-AzBootstrapEnvironment needs re-instating

2 participants