Skip to main content

🚀 InfraBot

PyPI version Documentation Status codecov

Create resource on the cloud with natural language using AI-powered Terraform generation

📖 Features

  • Natural language-based resource creation
  • Support for AWS cloud resources (S3 buckets, EC2 instances, etc.)
  • Local infrastructure development using LocalStack
  • Component-based infrastructure management
  • Interactive chat interface for cloud resources
  • Support for multiple infrastructure components
  • Self-healing infrastructure creation with automatic error fixing

🛠️ Prerequisites

  • Python 3.10 or higher
  • Required packages (to be installed via pip):
    pip install infrabot
    
  • Terraform installed:
    brew install terraform
    
  • AWS CLI configured:
    aws configure
    

P.S, make sure to configure the default region as well.

  • OpenAI API key:
    export OPENAI_API_KEY='your_api_key_here'
    
  • For local development:
    docker pull localstack/localstack
    docker run -d -p 4566:4566 localstack/localstack
    

📚 Command Structure

Initialize a new project:

infrabot init [--verbose] [--local]

Create a new component:

infrabot component create --prompt "Your infrastructure description" --name component-name [--verbose] [--force] [--model MODEL_NAME] [--self-healing] [--max-attempts N] [--keep-on-failure]

Delete all components:

infrabot component delete [--force]

Destroy all components infrastructure:

infrabot component destroy [--force]

Edit a component:

infrabot component edit component-name

Chat about your infrastructure:

infrabot chat component-name

Check InfraBot version:

infrabot version

📊 Usage Examples

  1. Initialize a new project:
infrabot init
  1. Create a web server component with self-healing:
infrabot component create --prompt "Create an EC2 instance with nginx installed" --name web-server --self-healing
  1. Create a local S3 bucket for testing:
infrabot component create --prompt "Create an S3 bucket" --name test-bucket --local
  1. Create a database component with custom retry attempts:
infrabot component create --prompt "Set up an RDS instance for PostgreSQL" --name database --self-healing --max-attempts 5
  1. Chat about your infrastructure:
infrabot chat web-server

🗂️ Project Structure

When you initialize a project, InfraBot creates a .infrabot directory with the following structure:

.infrabot/
└── default/
    ├── backend.tf
    ├── provider.tf
    ├── component1.tf
    ├── component2.tf
    └── ...

Each component is stored as a separate Terraform file in the workspace directory.

🔧 Advanced Features

Self-Healing Infrastructure Creation

InfraBot includes a self-healing feature that automatically fixes Terraform errors during resource creation:

  • Enable with --self-healing flag
  • Set maximum retry attempts with --max-attempts N (default: 3)
  • Uses AI to analyze errors and fix configuration issues
  • Maintains original infrastructure intent while resolving dependencies
  • Shows detailed fix explanations for transparency
  • Use --keep-on-failure to preserve generated Terraform files even when errors occur (useful for debugging)

Example with self-healing:

infrabot component create \
  --prompt "Create a highly available EC2 setup with auto-scaling" \
  --name ha-web \
  --self-healing \
  --max-attempts 5 \
  --keep-on-failure

If Terraform encounters errors during plan or apply:

  1. InfraBot analyzes the error output
  2. AI suggests fixes while preserving the original intent
  3. Retries the operation with fixed configuration
  4. Continues until success or max attempts reached
  5. If --keep-on-failure is set, preserves the generated Terraform files for inspection even if errors occur

Langfuse Monitoring

InfraBot supports observability and monitoring of AI interactions through Langfuse:

  • Set up Langfuse credentials:

    export LANGFUSE_PUBLIC_KEY='your_public_key'
    export LANGFUSE_SECRET_KEY='your_secret_key'
    
  • All AI interactions are automatically logged to your Langfuse dashboard

Alternative Models

InfraBot supports multiple AI models for infrastructure generation through LiteLLM integration. While OpenAI is the default provider, you can use other models by setting the appropriate API key and specifying the model:

Note: Even when using alternative models, the OPENAI_API_KEY environment variable is still required for certain auxiliary tasks within InfraBot.

Using Groq Models

export GROQ_API_KEY='your_api_key'
infrabot component create \
  --name eks-cluster-1 \
  --prompt "create an EKS cluster named MyKubernetesCluster" \
  --self-healing \
  --model "groq/deepseek-r1-distill-llama-70b"

Using Perplexity Models

export PERPLEXITY_API_KEY='your_api_key'
infrabot component create \
  --name eks-cluster-1 \
  --prompt "create an EKS cluster named MyKubernetesCluster" \
  --self-healing \
  --model "perplexity/sonar-pro"

Recommendation: We recommend using the perplexity/sonar-pro model for its enhanced factuality and accuracy in infrastructure generation.

The --model flag allows you to specify which model to use for infrastructure generation. Make sure to set the corresponding API key as an environment variable before running the command.

InfraBot supports all models available through LiteLLM (see LiteLLM Documentation), including but not limited to:

  • OpenAI (default), for instance: gpt-4o, o3-mini
  • Groq, for instance: groq/deepseek-r1-distill-llama-70b
  • Perplexity, for instance: perplexity/sonar-pro
  • Anthropic, for instance: anthropic/claude-3-5-sonnet
  • Google VertexAI
  • AWS Bedrock
  • Azure OpenAI
  • Hugging Face
  • And many more

Each provider requires its own API key to be set as an environment variable. Common examples:

  • OPENAI_API_KEY for OpenAI models (required for all setups)
  • GROQ_API_KEY for Groq models
  • PERPLEXITY_API_KEY for Perplexity models
  • ANTHROPIC_API_KEY for Anthropic models
  • AZURE_API_KEY for Azure OpenAI models

Refer to the LiteLLM documentation for the complete list of supported models and their corresponding environment variables.

Metadata

Release files for infrabot 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for infrabot 0.1.1
File Size Uploaded
infrabot-0.1.1.tar.gz 19.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for infrabot 0.1.1
File Interpreter ABI Platform
infrabot-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 42.3 kB

Release files / infrabot-0.1.1.tar.gz

Download URL infrabot-0.1.1.tar.gz
Size 19.4 kB
Tags Source
SHA-256 checksum
How to use checksums
27e5b653d177bf75321a1e562f7b12a7c6eeb5590a2c73f825e6bf0872bff77c
BLAKE2b-256 checksum
How to use checksums
0adaddad04d3ccd36aab7329c19b7a7863185d65c60bf3e56e35a8d213ec34b2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.10.15

Release files / infrabot-0.1.1-py3-none-any.whl

Download URL infrabot-0.1.1-py3-none-any.whl
Size 22.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cd8cc05d43bbf53c67419c4ab4a8237c2adea50674ab9520b338b9533e979862
BLAKE2b-256 checksum
How to use checksums
435feaef48defa055ac14fc2e4e9b793e30659fb850c22c93ae288a4c73e6a4c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.10.15

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page