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.0.tar.gz (71.3 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.0-py3-none-any.whl (49.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: bicep_whatif_advisor-3.5.0.tar.gz
  • Upload date:
  • Size: 71.3 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.0.tar.gz
Algorithm Hash digest
SHA256 378132ca3c941dc8b44730f4079128445b9f4734c9527b2a2a7e6eeaa9ceea2a
MD5 746e973a56673a082a712df8b7fc9c8d
BLAKE2b-256 1af824a62c9f5dba0ebc516e271e7828043161fe0846c4148a029dcbef797b17

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for bicep_whatif_advisor-3.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bfd2f8e5aa164800f0b27069881932524e44a386fea70bfa26437953eadf6510
MD5 05b5ecddb48ab12e3200fd082955340f
BLAKE2b-256 3713e5c2b9e9b4bf196966b329f8ca86dc810a64f588c7a2e8f44e01fa928f49

See more details on using hashes here.

Provenance

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