AI-Powered Infrastructure-as-Code Generator using Google Gemini API
Generate production-ready Terraform code for AWS, Azure, and GCP in seconds! This tool leverages Google's Gemini AI to create complete, well-structured Terraform configurations based on your requirements.
- π― Multi-Cloud Support: Generate Terraform code for AWS, Azure, and GCP
- π€ AI-Powered: Uses Google Gemini API for intelligent code generation
- π¦ Complete Structure: Generates all necessary Terraform files
- β¨ Best Practices: Follows Terraform and cloud provider best practices
- π Security-First: Includes security considerations and recommendations
- π± Single File: Entire application in one HTML file - no installation needed
- πΎ Export Ready: Copy individual files or download complete bundle
- π¨ Modern UI: Beautiful, responsive interface with cloud-themed design
The tool generates a complete Terraform project structure:
terraform-project/
βββ provider.tf # Cloud provider configuration
βββ variables.tf # Input variables with descriptions
βββ main.tf # Main resource definitions
βββ outputs.tf # Output values
βββ terraform.tfvars.example # Example variable values
βββ README.md # Project documentation
-
Gemini API Key (Free)
- Visit Google AI Studio
- Sign in with your Google account
- Click "Create API Key"
- Copy the generated key
-
Web Browser
- Any modern browser (Chrome, Firefox, Safari, Edge)
-
Open the Tool
# Simply open the HTML file in your browser open terraform-generator.html # or double-click the file
-
Enter Your API Key
- Paste your Gemini API key in the first field
-
Select Cloud Provider
- Click on AWS, Azure, or GCP card
-
Specify Services
Examples: AWS: ec2, rds, s3, vpc, lambda Azure: vm, sql-database, storage-account, vnet GCP: compute-instance, cloud-sql, storage-bucket, vpc -
Add Requirements (Optional)
Examples: - Use t3.micro for EC2 instances - Enable encryption at rest - Deploy in us-east-1 region - Add tags for production environment - Use multi-AZ for RDS -
Generate Code
- Click "π Generate Terraform Code"
- Wait for AI to generate your infrastructure code
- Review, copy, or download the generated files
Input:
- Cloud: AWS
- Services:
ec2, vpc, security-group - Requirements:
t3.micro instance, allow SSH from my IP
Output: Complete Terraform code with VPC, subnet, security group, and EC2 instance
Input:
- Cloud: Azure
- Services:
app-service, sql-database, storage-account - Requirements:
Standard tier, West Europe region, backup enabled
Output: Full Azure infrastructure for web app with database and storage
Input:
- Cloud: GCP
- Services:
compute-instance, cloud-sql, storage-bucket, pubsub - Requirements:
n1-standard-2, PostgreSQL 14, us-central1
Output: Complete GCP data infrastructure with compute, database, and messaging
- Compute: EC2, Lambda, ECS, EKS, Auto Scaling
- Storage: S3, EBS, EFS
- Database: RDS, DynamoDB, ElastiCache, Redshift
- Networking: VPC, Route53, CloudFront, API Gateway
- Security: IAM, KMS, Secrets Manager, WAF
- Compute: Virtual Machines, App Service, AKS, Functions
- Storage: Storage Account, Blob Storage, File Storage
- Database: SQL Database, Cosmos DB, MySQL, PostgreSQL
- Networking: Virtual Network, Load Balancer, Application Gateway
- Security: Key Vault, Active Directory, Security Center
- Compute: Compute Engine, GKE, Cloud Functions, Cloud Run
- Storage: Cloud Storage, Persistent Disk
- Database: Cloud SQL, Firestore, Bigtable, Spanner
- Networking: VPC, Cloud Load Balancing, Cloud CDN
- Security: IAM, KMS, Secret Manager
User Input β Gemini API β AI Processing β Terraform Code Generation β Structured Output
- Frontend: HTML5, CSS3, Vanilla JavaScript (ES6+)
- AI Model: Google Gemini (2.0-flash, 1.5-flash, 1.5-pro)
- Fonts: Inter (UI), JetBrains Mono (Code)
- API: Google Generative AI SDK
The tool attempts multiple Gemini models in order:
gemini-2.0-flash-exp(Latest experimental)gemini-2.0-flash(Latest stable)gemini-1.5-flash(Fast and efficient)gemini-1.5-pro(Most capable)
If one model fails, it automatically tries the next one.
- Be Specific: Include instance types, regions, and sizing requirements
- Use Standard Names: Stick to official service names (e.g., "ec2" not "virtual machine" for AWS)
- Add Context: Mention environment (dev/staging/prod) for appropriate configurations
- Security First: Request encryption, IAM roles, and security groups explicitly
- Review Generated Code: Always review before applying
- Customize Variables: Adjust
terraform.tfvars.examplefor your environment - Test in Dev First: Deploy to development environment before production
- Version Control: Commit generated code to Git
- State Management: Configure remote state (S3, Azure Storage, GCS)
- API Key: Your Gemini API key is used only in your browser, never stored
- Generated Code: Review security groups, IAM policies, and encryption settings
- Secrets: Never commit
terraform.tfvarswith real credentials to Git - State Files: Use remote state with encryption and access controls
Issue: "All models failed" error
- Solution: Check your API key is valid and has quota remaining
- Visit Google AI Studio to verify
Issue: Generated code has syntax errors
- Solution: Try regenerating with more specific requirements
- Simplify your service list and add requirements one at a time
Issue: Missing services in output
- Solution: Use official service names (check supported services list)
- Be explicit about all required resources
Issue: Code doesn't match cloud provider
- Solution: Ensure you selected the correct cloud provider card
- Verify service names are appropriate for that provider
Contributions are welcome! Here are some ideas:
- Add support for more cloud providers (Oracle Cloud, DigitalOcean)
- Implement Terraform module generation
- Add syntax highlighting for code blocks
- Create preset templates for common architectures
- Add validation for generated code
- Implement direct GitHub export
MIT License - feel free to use this tool for personal or commercial projects.
- Google Gemini: For providing the AI capabilities
- HashiCorp: For creating Terraform
- Cloud Providers: AWS, Azure, and GCP for their excellent documentation
- Issues: Found a bug? Open an issue on GitHub
- Questions: Need help? Check the troubleshooting section
- Feature Requests: Have an idea? Submit a feature request
- Add Terraform Cloud integration
- Support for Terragrunt configurations
- Multi-region deployments
- Cost estimation integration
- Terraform plan preview
- Export to GitHub repository
- Template library for common patterns
- Kubernetes manifest generation
- Ansible playbook generation
- Initial release
- Multi-cloud support (AWS, Azure, GCP)
- Complete Terraform file generation
- Modern UI with copy/download features
- Model fallback strategy
- Production-ready code generation
Built with β€οΈ for the DevOps community
Making Infrastructure-as-Code accessible to everyone!