An AI agent that generates Terraform code using Azure Verified Modules (AVM)
Project description
Terraform AVM Agent
An AI agent built with the Microsoft Agent Framework that generates Terraform code using Azure Verified Modules (AVM).
Features
- Service-Based Generation: Provide a list of Azure services and get a complete Terraform project
- Architecture Diagram Analysis: Upload an architecture diagram and the agent will identify services and generate code
- Interactive Chat Mode: Have a conversation with the agent to explore modules and generate code
- AVM Module Registry: Built-in knowledge of 40+ Azure Verified Modules
- Production-Ready Output: Generated code follows Terraform best practices
Installation
# Core CLI (list-modules, search, info, version, etc.)
pip install tf-avm-agent
# With AI agent support (chat, generate --interactive, diagram analysis)
pip install "tf-avm-agent[agent]"
# With API server
pip install "tf-avm-agent[api]"
# Everything
pip install "tf-avm-agent[all]"
# Development
pip install -e ".[dev]"
Extras
| Extra | What it adds |
|---|---|
agent |
AI agent, diagram analysis (agent-framework, azure-identity, pillow, jinja2) |
api |
REST API server (fastapi, uvicorn) |
lightning |
RL training (agentlightning) |
all |
All of the above |
dev |
all + pytest, ruff, mypy, build, twine |
Prerequisites
- Python 3.10+
- An OpenAI API key or Azure OpenAI endpoint (for AI features)
- Terraform 1.9+ (for running generated code)
Set your API key:
export OPENAI_API_KEY="your-api-key"
# Or for Azure OpenAI
export AZURE_OPENAI_ENDPOINT="https://your-endpoint.openai.azure.com"
export AZURE_OPENAI_API_KEY="your-api-key"
Quick Start
Generate from Services List
# Generate Terraform for VM, storage, and key vault
tf-avm-agent generate -s "vm,storage,keyvault" -n "my-project" -o ./terraform
# Generate with specific location
tf-avm-agent generate -s "aks,acr,postgresql" -n "microservices" -l "westeurope" -o ./infra
Interactive Chat Mode
tf-avm-agent chat
Example conversation:
You: Generate Terraform for a web application with a database
Agent: I'll help you create a Terraform project for a web application with a database...
[Generates code using AVM modules for App Service, SQL Database, etc.]
List Available Modules
# List all modules
tf-avm-agent list-modules
# List by category
tf-avm-agent list-modules -c networking
# Get module info
tf-avm-agent info virtual_machine
Search for Modules
tf-avm-agent search "kubernetes"
tf-avm-agent search "database"
Python API
from tf_avm_agent import TerraformAVMAgent, generate_terraform
# Quick generation
result = generate_terraform(
services=["virtual_machine", "storage_account", "key_vault"],
project_name="my-app",
output_dir="./terraform"
)
# Using the agent class
agent = TerraformAVMAgent()
# Generate from services
result = agent.generate_from_services(
services=["aks", "acr", "postgresql"],
project_name="microservices",
location="westeurope"
)
# Interactive with AI
response = agent.run("Create Terraform for a secure web app with monitoring")
# Analyze architecture diagram
response = agent.analyze_diagram(
image_path="./architecture.png",
project_name="cloud-app"
)
Available Modules
The agent includes knowledge of 40+ Azure Verified Modules across categories:
| Category | Modules |
|---|---|
| Compute | Virtual Machine, VMSS, Container Apps, AKS, Functions, App Service |
| Networking | Virtual Network, NSG, Application Gateway, Load Balancer, Front Door, Firewall |
| Storage | Storage Account (Blob, Files, Queue, Table) |
| Database | SQL Server, PostgreSQL, MySQL, Cosmos DB, Redis |
| Security | Key Vault, Managed Identity |
| Messaging | Event Hub, Service Bus, Event Grid |
| Monitoring | Log Analytics, Application Insights |
| AI | Cognitive Services, Azure OpenAI, Machine Learning, AI Search |
Generated Project Structure
my-project/
├── providers.tf # Provider configuration
├── variables.tf # Input variables
├── main.tf # Resource definitions using AVM modules
├── outputs.tf # Output values
├── terraform.tfvars.example # Example variable values
├── .gitignore # Git ignore file
└── README.md # Project documentation
Example Generated Code
# main.tf
module "virtual-machine" {
source = "Azure/avm-res-compute-virtualmachine/azurerm"
version = "0.18.0"
name = "virtual-machine"
resource_group_name = azurerm_resource_group.main.name
location = azurerm_resource_group.main.location
virtualmachine_sku_size = "Standard_D2s_v3"
virtualmachine_os_type = "Linux"
}
module "storage-account" {
source = "Azure/avm-res-storage-storageaccount/azurerm"
version = "0.5.0"
name = "storage-account"
resource_group_name = azurerm_resource_group.main.name
location = azurerm_resource_group.main.location
account_tier = "Standard"
account_replication_type = "LRS"
}
Configuration
Environment Variables
| Variable | Description |
|---|---|
OPENAI_API_KEY |
OpenAI API key for AI features |
AZURE_OPENAI_ENDPOINT |
Azure OpenAI endpoint |
AZURE_OPENAI_API_KEY |
Azure OpenAI API key |
AZURE_OPENAI_DEPLOYMENT |
Azure OpenAI deployment name |
CLI Options
tf-avm-agent --help
tf-avm-agent generate --help
tf-avm-agent chat --help
Architecture
flowchart TB
subgraph Agent["Terraform AVM Agent"]
direction TB
CLI["CLI Interface<br/>(Typer + Rich)"]
subgraph Core["Agent Core"]
direction TB
MAF["Microsoft Agent Framework"]
DA["Diagram Analyzer"]
AVM["AVM Module Lookup"]
TG["Terraform Generator"]
MAF --> DA
MAF --> AVM
MAF --> TG
end
Registry["AVM Module Registry<br/>(105 modules)"]
CLI --> Core
Core --> Registry
end
Development
# Install development dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Run linting
ruff check src/
# Type checking
mypy src/
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
🤖 Fun fact: This project was built with significant contributions from GitHub Copilot and Claude. They wrote most of the code while the human mostly typed "fix this" and "that doesn't work". The AI agents are still waiting for their contributor badges.
License
MIT License - see LICENSE file for details.
Resources
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tf_avm_agent-0.2.0.tar.gz.
File metadata
- Download URL: tf_avm_agent-0.2.0.tar.gz
- Upload date:
- Size: 180.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9a142162064ef9e6387aad81324ffa81e60a6d5d9fcffc3ba1bb3da8ed0624aa
|
|
| MD5 |
3d5ff57e7e4f1919ce25106a0c3c30a1
|
|
| BLAKE2b-256 |
0882127760d44a935683270a114bf31c7024e8eb1ff48d7a2bc1457932003433
|
Provenance
The following attestation bundles were made for tf_avm_agent-0.2.0.tar.gz:
Publisher:
release.yml on sujaypillai/tf-avm-agent
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tf_avm_agent-0.2.0.tar.gz -
Subject digest:
9a142162064ef9e6387aad81324ffa81e60a6d5d9fcffc3ba1bb3da8ed0624aa - Sigstore transparency entry: 1340641243
- Sigstore integration time:
-
Permalink:
sujaypillai/tf-avm-agent@9c4b8a407837920cd3f4d0de3a4487b19af93787 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/sujaypillai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@9c4b8a407837920cd3f4d0de3a4487b19af93787 -
Trigger Event:
release
-
Statement type:
File details
Details for the file tf_avm_agent-0.2.0-py3-none-any.whl.
File metadata
- Download URL: tf_avm_agent-0.2.0-py3-none-any.whl
- Upload date:
- Size: 69.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b50f4c54a678440127d2323069f222921220d4de62f7efee3c90a3ea238b9eeb
|
|
| MD5 |
e5db229f0ec3c49d36e6a0efd77df5c9
|
|
| BLAKE2b-256 |
72df0a23b0647df52498a0c274cd52ed118df780dad27d08d0869efeb2ac1ba3
|
Provenance
The following attestation bundles were made for tf_avm_agent-0.2.0-py3-none-any.whl:
Publisher:
release.yml on sujaypillai/tf-avm-agent
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tf_avm_agent-0.2.0-py3-none-any.whl -
Subject digest:
b50f4c54a678440127d2323069f222921220d4de62f7efee3c90a3ea238b9eeb - Sigstore transparency entry: 1340641256
- Sigstore integration time:
-
Permalink:
sujaypillai/tf-avm-agent@9c4b8a407837920cd3f4d0de3a4487b19af93787 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/sujaypillai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@9c4b8a407837920cd3f4d0de3a4487b19af93787 -
Trigger Event:
release
-
Statement type: