This repository automates the cleanup of outdated Azure snapshots by identifying and listing snapshots older than a specified number of days. It uses Azure Resource Graph queries to fetch snapshot details and logs the results for further processing.
- Identify Azure snapshots older than a specified number of days.
- Fetch subscription IDs dynamically using subscription names.
- Paginated querying for large datasets to handle thousands of snapshots efficiently.
- Logging support for debugging and monitoring.
- Python: Ensure Python 3.8+ is installed.
- Azure CLI: Install and authenticate using the Azure CLI.
- Azure SDK for Python: Install the required Azure SDK libraries.
- Environment Variables: Create a
.env
file with the following variables:AZURE_CLIENT_ID
AZURE_TENANT_ID
AZURE_CLIENT_SECRET
LOGGING_CONFIG
=logging-conf.yaml
-
Clone the repository:
git clone https://github.com/githubofkrishnadhas/azure-decommision-old-snapshots.git cd azure-decommision-old-snapshots
-
Install the required packages:
poetry install
-
Set up logging configuration:
Ensure logging-conf.yaml exists in the root directory or provide a custom path via the LOGGING_CONFIG environment variable.
-
Initiate poetry venv
poetry shell
-
Run the script:
poetry run python snapshot.py --subscription_name SUBSCRIPTION_NAME --days DAYS --dry_run
- --dry_run: If specified, the script will only log the snapshots that would be deleted without actually deleting them. This is useful for testing and verification before performing the actual deletion.
- snapshot.py: Main script for identifying and processing old snapshots.
- resourcegraph.py: Contains functions to query Azure Resource Graph for subscriptions and snapshots.
- setup_logging.py: Configures logging for the application.
- README.md: Documentation for the repository.