A conversational AI agent that provisions and manages cloud infrastructure through natural language interactions, powered by Agentic AI, MCP (Model Context Protocol), and Terraform.
- π£οΈ Natural Language Interface: "Create a VM in AWS" β Provisions EC2 instance
- π Secure Credential Management: AWS credentials never exposed to LLMs
- ποΈ Terraform Backend: Professional infrastructure-as-code approach
- π MCP Integration: Secure tool communication protocol
- π° Cost Estimation: Shows estimated costs before provisioning
- π€ Multi-User Support: User authentication and RBAC
- π Real-time Chat UI: Modern web interface with Streamlit
- π Audit Logging: Complete audit trail of all operations
- π Multi-Cloud Ready: Extensible for AWS, Azure, GCP
graph TB
subgraph "Frontend Layer"
UI[Web Chat Interface]
API[REST API Gateway]
end
subgraph "Agent Layer"
AGENT[AI Agent Engine]
NLP[Intent Parser]
RESP[Response Generator]
end
subgraph "MCP Layer"
CLIENT[MCP Client]
SERVER[Terraform MCP Server]
end
subgraph "Security Layer"
AUTH[User Authentication]
CREDS[Encrypted Credential Store]
RBAC[Role-Based Access Control]
end
subgraph "Terraform Engine"
TEMPLATES[Template Generator]
CLI[Terraform CLI]
STATE[State Management]
end
subgraph "Cloud Providers"
AWS[AWS APIs]
AZURE[Azure APIs]
GCP[GCP APIs]
end
subgraph "Storage"
DB[(User Profiles DB)]
TFSTATE[(Terraform State)]
LOGS[(Audit Logs)]
end
UI --> API
API --> AGENT
AGENT --> NLP
AGENT --> RESP
AGENT --> CLIENT
CLIENT --> SERVER
SERVER --> AUTH
AUTH --> CREDS
AUTH --> RBAC
SERVER --> TEMPLATES
TEMPLATES --> CLI
CLI --> STATE
CLI --> AWS
CLI --> AZURE
CLI --> GCP
AUTH --> DB
STATE --> TFSTATE
SERVER --> LOGS
style AGENT fill:#e1f5fe
style SERVER fill:#f3e5f5
style CREDS fill:#ffebee
style CLI fill:#e8f5e8
- Python 3.11+
- PostgreSQL 12+
- Terraform 1.0+
- Docker (optional)
git clone <your-repo>
cd infrastructure-agent
# Run the setup script
python setup.py
# Or use make
make setupcp .env.example .envEdit .env with your settings:
# Database
DATABASE_URL=postgresql://user:pass@localhost:5432/infraagent
# Security (generate proper keys for production!)
SECRET_KEY=your-jwt-secret-key-here
ENCRYPTION_KEY=your-fernet-encryption-key-here
# API
API_HOST=0.0.0.0
API_PORT=8000
# Logging
LOG_LEVEL=INFOpip install -r requirements.txt
# Or: make install# Start PostgreSQL (if not running)
# Then create tables
make init-db# Start both API and frontend
make dev
# Or run separately:
python app.py & # API server (port 8000)
streamlit run frontend/app.py # Frontend (port 8501)- Frontend: http://localhost:8501
- API Docs: http://localhost:8000/docs
- Default Login: username=
admin, password=admin123
User: "Create a VM in AWS"
Agent: "I'll create a t3.micro EC2 instance in us-east-1.
Estimated cost: $10.50/month. Shall I proceed?"
User: "Yes, apply it"
Agent: "β
EC2 instance created successfully!
Instance ID: i-1234567890abcdef0
Public IP: 54.123.45.67"
User: "Set up a database with web server"
Agent: "I'll provision:
β’ EC2 instance (t3.micro) for web server
β’ RDS MySQL database (db.t3.micro)
β’ Security groups for proper access
Estimated monthly cost: $35.80
Should I create this infrastructure?"
User: "What infrastructure do I have running?"
Agent: "Current resources:
β’ 2 EC2 instances (us-east-1)
β’ 1 RDS database (MySQL 8.0)
β’ 1 S3 bucket
β’ 1 Application Load Balancer
Total estimated cost: $127.50/month"
User: "Scale my web servers to 3 instances in Oregon"
User: "Create a development environment"
User: "Set up CI/CD infrastructure with S3 and CodeBuild"
User: "Show me cost breakdown by service"
User: "Destroy all resources in staging environment"
- Web Interface: Configure AWS credentials in the sidebar
- API: Use
/auth/loginendpoint for authentication - Database: Users stored in PostgreSQL with encrypted credentials
The system securely stores AWS credentials per user:
# Credentials are encrypted and never exposed to LLMs
await credential_manager.store_user_credentials(
user_id="user123",
provider="aws",
credentials={
"aws_access_key": "AKIA...",
"aws_secret_key": "xyz...",
"region": "us-east-1"
}
)- Create Terraform Template: Add to
mcp/server/templates/aws/ - Update Intent Parser: Add resource patterns to
agent/intent_parser.py - Add MCP Tool: Extend
mcp/server/terraform_server.py
Example template (new_resource.tf.j2):
resource "aws_new_service" "{{ resource_name }}" {
name = "{{ resource_name }}-{{ environment }}"
type = "{{ config.type | default('standard') }}"
tags = {
Name = "{{ resource_name }}-{{ environment }}"
Environment = "{{ environment }}"
ManagedBy = "InfraAgent"
}
}
output "{{ resource_name }}_id" {
value = aws_new_service.{{ resource_name }}.id
}# Run all tests
make test
# Test specific components
python -m pytest tests/test_agent.py -v
python -m pytest tests/test_mcp.py -v
python -m pytest tests/test_terraform.py -v# Test agent functionality
python -c "
from agent.main import InfraAgent
from agent.intent_parser import IntentParser
parser = IntentParser()
intent = parser.parse('Create a VM in AWS')
print(intent)
"
# Test MCP client
python mcp/client.pydocker-compose up -d# Build image
docker build -t infrastructure-agent .
# Run with proper environment
docker run -e DATABASE_URL="postgresql://..." \
-e SECRET_KEY="..." \
-p 8000:8000 \
infrastructure-agent- β AWS credentials encrypted with Fernet
- β Never passed to LLM models
- β Isolated in MCP server process
- β User-specific credential storage
- β JWT-based authentication
- β Role-based access control (RBAC)
- β Session management
- β Password hashing with PBKDF2
- β Terraform state encryption
- β Audit logging for all operations
- β Resource tagging for ownership
- β Network security groups by default
# View real-time logs
tail -f logs/infraagent.log
# View specific user actions
grep "user-123" logs/infraagent.log-- Check recent infrastructure requests
SELECT * FROM infrastructure_requests
ORDER BY created_at DESC LIMIT 10;
-- View audit logs
SELECT action, resource_type, timestamp
FROM audit_logs
WHERE user_id = 'user-123'
ORDER BY timestamp DESC;The system provides cost estimates before provisioning:
- Real-time cost calculation
- Monthly cost projections
- Resource cost breakdown
- Budget alerts (planned feature)
infrastructure-agent/
βββ agent/ # AI agent core logic
β βββ main.py # Agent orchestrator
β βββ intent_parser.py # NLP intent parsing
β βββ response_generator.py
βββ mcp/ # MCP client/server
β βββ client.py # MCP client
β βββ server/ # Terraform MCP server
βββ security/ # Auth & credentials
β βββ auth.py # Authentication
β βββ credentials.py # Encrypted storage
β βββ rbac.py # Access control
βββ frontend/ # Streamlit UI
βββ terraform/ # TF workspaces & modules
βββ database/ # SQLAlchemy models
-
New Cloud Provider:
- Add templates in
mcp/server/templates/azure/ - Extend
intent_parser.pypatterns - Add provider-specific tools
- Add templates in
-
New Resource Types:
- Create Terraform template
- Update intent parsing
- Add cost estimation logic
-
Enhanced AI:
- Improve natural language processing
- Add conversation context
- Implement learning from user preferences
| Endpoint | Method | Description |
|---|---|---|
/chat |
POST | Main chat interface |
/confirm-action |
POST | Confirm infrastructure changes |
/auth/login |
POST | User authentication |
/resources |
GET | List user resources |
/costs |
GET | Get cost estimates |
/audit |
GET | Audit log access |
- Fork the repository
- Create feature branch:
git checkout -b feature/amazing-feature - Run tests:
make test - Submit pull request
- Use Black for formatting:
black . - Follow PEP 8 conventions
- Add type hints for all functions
- Write comprehensive docstrings
1. Database Connection Error
# Check PostgreSQL is running
sudo systemctl status postgresql
# Verify database URL in .env
echo $DATABASE_URL2. MCP Server Connection Failed
# Check if MCP server is running
ps aux | grep terraform_server
# Verify port availability
netstat -ln | grep 80013. Terraform Execution Failed
# Check Terraform installation
terraform --version
# Verify AWS credentials
aws sts get-caller-identity4. Frontend Not Loading
# Check if Streamlit is running
ps aux | grep streamlit
# Verify port 8501 is available
curl http://localhost:8501Enable debug logging:
export LOG_LEVEL=DEBUG
python app.py# Reset database
make reset-db
# Clean workspaces
make clean
# Restart services
make devThis project is licensed under the MIT License - see the LICENSE file for details.
- Anthropic for Claude AI and MCP protocol
- HashiCorp for Terraform
- Streamlit for the amazing web framework
- FastAPI for the robust API framework
π Happy Infrastructure Provisioning!
Start with: make setup && make dev and visit http://localhost:8501