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.7.0.tar.gz (73.4 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.7.0-py3-none-any.whl (51.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: bicep_whatif_advisor-3.7.0.tar.gz
  • Upload date:
  • Size: 73.4 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.7.0.tar.gz
Algorithm Hash digest
SHA256 4cce6c05a4d16eaf1b430054f71355635a0cac58d8026d4f327c8577c86b1b7a
MD5 0563e2d9a1f033c47a2b774684568560
BLAKE2b-256 b75c1ae44e2798795fdf0c56c6ccf4c11591d3c6222e1985591da99b624be4a8

See more details on using hashes here.

Provenance

The following attestation bundles were made for bicep_whatif_advisor-3.7.0.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.7.0-py3-none-any.whl.

File metadata

File hashes

Hashes for bicep_whatif_advisor-3.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b02bf3f4e16362bdcf994b2b55b788db8cb7c5c7954682273fbd13f62b36b292
MD5 188a421612c6e64cf177d05cf939fbe8
BLAKE2b-256 20ed2406f0a889bb35a75e24b2af14cd5183369199bd363d240db01342ee3a5e

See more details on using hashes here.

Provenance

The following attestation bundles were made for bicep_whatif_advisor-3.7.0-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