Skip to main content

AI-powered Azure Bicep What-If deployment advisor with automated safety reviews

Project description

bicep-whatif-advisor

Tests PyPI version Python versions License: MIT

AI-powered deployment safety gate for Azure Bicep and ARM templates. Pipe Azure What-If output through an LLM (Anthropic Claude, Azure OpenAI, or Ollama) to detect infrastructure drift, validate PR intent alignment, and evaluate custom risk dimensions. Integrates into GitHub Actions and Azure DevOps with zero-config platform detection, automatic PR comments, and configurable risk thresholds. Also works as a standalone CLI for local What-If analysis.

How It Works

Pipe Azure What-If output to the tool in your CI/CD pipeline. It auto-detects the platform, collects PR metadata and code diff, then sends everything to the LLM for analysis across two built-in risk categories:

  • Infrastructure Drift - Detects changes not in your code (out-of-band modifications)
  • PR Intent Alignment - Ensures changes match PR description

You can also add custom risk assessment agents via markdown files to evaluate additional dimensions like compliance, cost, risky operations, or naming conventions. See Custom Agents below.

Known Azure What-If noise (etag, provisioningState, etc.) is filtered before LLM analysis. Results are posted as a PR comment and the pipeline exits with code 0 (safe) or 1 (unsafe) based on configurable thresholds.

Example PR Comment:

production What-If Summary (non-blocking)

Risk Assessment Risk Level Key Concerns
Infrastructure Drift High Existing Paris Key Vault being modified when not present in code diff
PR Intent Alignment High PR intends to add Berlin branch but What-If shows Paris branch changes

Summary: The What-If output shows modifications to existing Paris branch resources rather than creating new Berlin branch resources. Most changes appear to be template refactoring (hardcoded to dynamic references) and What-If noise (retention policies, metadata). The only significant change is disabling public network access on an existing Key Vault.

📁 View changed resources (1 High Confidence)...
⚠️ Potential Azure What-If Noise (10 Low Confidence)...
📂 Raw What-If Output...

Verdict: ❌ UNSAFE

Reasoning: This deployment is unsafe due to a complete mismatch between PR intent (adding Berlin branch) and What-If output (modifying existing Paris Key Vault). The changes indicate both infrastructure drift and unintended modifications to existing resources not mentioned in the PR description.


Generated by bicep-whatif-advisor

Quick Start

GitHub Actions:

- name: Deployment Safety Gate
  env:
    ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  run: |
    pip install bicep-whatif-advisor[anthropic]
    az deployment group what-if \
      --resource-group ${{ vars.AZURE_RESOURCE_GROUP }} \
      --template-file main.bicep \
      --exclude-change-types NoChange Ignore \
      | bicep-whatif-advisor

Azure DevOps:

- script: |
    pip install bicep-whatif-advisor[anthropic]
    az deployment group what-if \
      --resource-group $(RESOURCE_GROUP) \
      --template-file main.bicep \
      --exclude-change-types NoChange Ignore \
      | bicep-whatif-advisor
  env:
    ANTHROPIC_API_KEY: $(ANTHROPIC_API_KEY)
    SYSTEM_ACCESSTOKEN: $(System.AccessToken)

Configuration

Risk Thresholds

Each risk bucket has an independent threshold: low, medium, high (default: high — most permissive).

# Block on medium or high risk
bicep-whatif-advisor \
  --drift-threshold medium \
  --intent-threshold medium

Skip individual buckets with --skip-drift or --skip-intent.

Custom Agents

Add custom risk assessment dimensions using markdown files with YAML frontmatter. Each file defines a new risk bucket that runs alongside the built-in ones:

---
id: compliance
display_name: Compliance Review
default_threshold: high
---

**Compliance Risk:**
Evaluate whether changes comply with organizational policies.

Risk levels for compliance:
- high: Encryption disabled, public access enabled, data residency violations
- medium: Policy assignment changes, unapproved resource types
- low: Tag updates for compliance metadata, monitoring additions

Point the tool at a directory of agent files:

bicep-whatif-advisor --ci \
  --agents-dir ./agents/ \
  --agent-threshold compliance=medium

Custom agents support --agent-threshold for per-agent thresholds and --skip-agent to disable individual agents. See the User Guide for details.

LLM Providers

Defaults to Anthropic Claude. Also supports Azure OpenAI and Ollama:

# Azure OpenAI
pip install bicep-whatif-advisor[azure]
bicep-whatif-advisor --provider azure-openai

# Local Ollama
pip install bicep-whatif-advisor[ollama]
bicep-whatif-advisor --provider ollama --model llama3.1

Config File

Define settings in a YAML file instead of passing many CLI flags. CLI flags always override config values:

# whatif-config.yaml
provider: azure-openai
ci: true
drift_threshold: medium
agents_dir: ./agents
bicep-whatif-advisor --config-file whatif-config.yaml

Additional Options

# Output formats: table (default), json, markdown
bicep-whatif-advisor --format json

# Include raw What-If output in PR comment
bicep-whatif-advisor --include-whatif

# Label comments for multi-environment pipelines
bicep-whatif-advisor --comment-title "Production"

# Non-blocking mode (report without failing pipeline)
bicep-whatif-advisor --no-block

See the User Guide for all CLI flags and the CI/CD Integration Guide for complete pipeline setup.

Documentation

Support

  • Issues: Report bugs or request features via repository issues
  • Contributing: Pull requests welcome!
  • License: MIT - see LICENSE for details

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bicep_whatif_advisor-3.5.5.tar.gz (72.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bicep_whatif_advisor-3.5.5-py3-none-any.whl (50.9 kB view details)

Uploaded Python 3

File details

Details for the file bicep_whatif_advisor-3.5.5.tar.gz.

File metadata

  • Download URL: bicep_whatif_advisor-3.5.5.tar.gz
  • Upload date:
  • Size: 72.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for bicep_whatif_advisor-3.5.5.tar.gz
Algorithm Hash digest
SHA256 3ca95420ec5766e4973183a7a99a7cf1d50700424b3f37a803237d5ec09f3600
MD5 7b171d167aecc83f27ae07e756bdc798
BLAKE2b-256 ad8b1c7d0e2a23b70d4f19dfe39353fb054323aebcae51ae1a56c5854c3b6b78

See more details on using hashes here.

Provenance

The following attestation bundles were made for bicep_whatif_advisor-3.5.5.tar.gz:

Publisher: publish-pypi.yml on neilpeterson/bicep-whatif-advisor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bicep_whatif_advisor-3.5.5-py3-none-any.whl.

File metadata

File hashes

Hashes for bicep_whatif_advisor-3.5.5-py3-none-any.whl
Algorithm Hash digest
SHA256 128e57f167bb01735a5f83d324c74eab2a6a613c937aba61cd7b9ac35ad64968
MD5 74aa07202522f6c9187f99f41d7f7e63
BLAKE2b-256 a15be2db94b7c06c9d64e05c07b8642e1bd283e01bf94b5d21aea28d328c1f9f

See more details on using hashes here.

Provenance

The following attestation bundles were made for bicep_whatif_advisor-3.5.5-py3-none-any.whl:

Publisher: publish-pypi.yml on neilpeterson/bicep-whatif-advisor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page