Automated Infrastructure as Code Generator
Project description
⚡ SimpleTerraform
❤️ By Sourav Kumar Singh Email: 1109souravkumar@gmail.com
Automated Infrastructure-as-Code (IaC) Generator
Build production-ready Terraform modules in seconds using an interactive CLI.
SimpleTerraform removes the boilerplate from Terraform. Instead of writing hundreds of lines of HCL from scratch, answer a few questions in your terminal, and let the tool generate best-practice infrastructure for you.
🚀 Features
- Interactive UI: Beautiful terminal interface with arrow-key navigation and validation.
- Modular Architecture: Generates clean, reusable Terraform modules.
- Smart Linking: Automatically detects dependencies (e.g., links EC2 instances to your specific VPCs).
- Validation: Prevents errors before they happen (validates CIDRs, S3 names, AMI formats).
- State Management: Saves your configuration to JSON so you can regenerate or modify later without re-typing everything.
📦 Installation
Option 1: Install via PyPI (Recommended)
pip install simpleterraform
🏗️ Usage
Once installed, simply run the command:
simpleterraform
The Workflow
- Start the tool: You will see the main menu.
- Generate Networking: Start by creating a VPC (Networking module).
- Add Layers: Add Security Groups, Compute, Databases, or Kubernetes clusters.
- Deploy: The tool generates a
root/folder withmain.tf.
cd root
terraform init
terraform apply
🏗️ System Architecture
Understanding how SimpleTerraform works under the hood helps you utilize it better. It follows a Model-View-Controller (MVC) pattern adapted for a CLI.
[Image of software architecture diagram]
- Input Layer (UI): Captures user intent via interactive prompts (
questionary). - Validation Layer (Model): Strictly validates data (CIDR ranges, naming conventions) using
Pydantic. - State Layer: Persists valid configurations into
metadata/<project>.json. - Generator Layer: Reads the JSON state and renders Jinja2 templates into valid Terraform (
.tf) files.
⚠️ Important Warnings & Best Practices
While this tool automates code generation, Infrastructure-as-Code requires careful management.
-
Always Audit the Code:
- The tool generates standard Terraform code. Always review the generated
.tffiles inroot/andterraform_modules/before runningapply. - Ensure the instance types and scaling limits fit your budget.
- The tool generates standard Terraform code. Always review the generated
-
Terraform Plan is Mandatory:
- Never run
terraform applyblindly. Always runterraform planfirst to see exactly what AWS resources will be created, modified, or destroyed.
- Never run
-
State Management:
- This tool generates a local Terraform state setup. For production teams, you should manually configure a Remote Backend (S3 + DynamoDB) in the generated
root/main.tffile to handle state locking.
- This tool generates a local Terraform state setup. For production teams, you should manually configure a Remote Backend (S3 + DynamoDB) in the generated
-
Cost Implications:
- Resources like NAT Gateways, Application Load Balancers, and RDS instances cost money per hour. Remember to
terraform destroyif you are just testing.
- Resources like NAT Gateways, Application Load Balancers, and RDS instances cost money per hour. Remember to
📏 Operational Rules
To ensure the tool works correctly, follow these rules:
-
Dependency Order Matters:
- You cannot create an EC2 Instance without a Network.
- You cannot create a Load Balancer without Security Groups.
- The Tool will block you if you try to skip steps, but keep this logical flow in mind.
-
Do Not Edit Metadata Manually:
- The files inside
metadata/are the source of truth for the generator. If you edit them manually and make a syntax error, the tool may fail to load your project.
- The files inside
-
Regeneration Overwrites:
- If you run the generator again for the same project, it will overwrite the
.tffiles. If you made manual changes to the generated files, they will be lost. Make your changes via the CLI tool whenever possible.
- If you run the generator again for the same project, it will overwrite the
🔮 What You Can Do From Here
The generated code is a foundation. Here is how you can take it to the next level:
- Integration with CI/CD: Commit the generated
root/andterraform_modules/folders to GitHub/GitLab and set up a pipeline to deploy automatically. - Add Custom Providers: The tool defaults to
us-east-1. You can easily change theprovider "aws"block inroot/main.tfto deploy to other regions or add providers like Cloudflare or Datadog. - Secret Management: The tool accepts passwords for RDS. For production, replace these hardcoded strings in
main.tfwith references to AWS Secrets Manager or Terraform Variables.
🛡️ Supported Modules
| Module | Description | Key Features |
|---|---|---|
| Networking | VPC, Subnets, IGW, NAT | Automatic subnet calculation, Multi-AZ support. |
| Security | Security Groups | Rule descriptions, Ingress/Egress management. |
| Compute | EC2 Instances | Root volume encryption, Public/Private placement. |
| Auto Scaling | ASG & Launch Templates | Dynamic scaling policies, Health checks. |
| EKS | Kubernetes Clusters | Managed Node Groups, IAM Roles handling. |
| ECS | Fargate Clusters | Serverless containers, Task Definitions. |
| Database | RDS (Postgres/MySQL) | Storage encryption, Multi-AZ, Subnet groups. |
| Load Balancer | ALB | HTTP->HTTPS redirection, Target Groups. |
| Storage | S3 Buckets | Versioning, Server-side encryption, Public access block. |
| IAM | Roles & Policies | Least privilege policy builder. |
| Monitoring | CloudWatch & SNS | Alarms for CPU, Database connections, and 5xx errors. |
📂 Project Structure
When you run the tool, it creates the following structure in your working directory:
.
├── metadata/ # JSON files storing your answers (The State)
├── terraform_modules/ # Generated reusable modules (The Logic)
│ ├── my-project-networking-1/
│ ├── my-project-security-1/
│ └── ...
└── root/ # The entry point for Terraform
├── main.tf # Connects all modules together
├── variables.tf
└── outputs.tf
System Overview
The architecture is divided into three distinct planes:
- The Interaction Plane: Captures and validates user intent.
- The State Plane: The persistent "Source of Truth."
- The Execution Plane: The engine that reconciles state into infrastructure code.
Component Breakdown
A. The Interface Gateway (CLI Controller)
- Component:
main.py&ui.py - Role: The entry point for all operations.
- Function: It acts as the API Server for the system. It routes user requests (Generate, View, Exit) to the appropriate logic handlers. It does not process data itself; it delegates tasks to the underlying controllers.
B. The Admission Controller (Validation Engine)
- Component:
src/models.py(Pydantic) - Role: The Guardrails.
- Function: Before any data is persisted to the state, it passes through this layer. It enforces strict schema rules (e.g., CIDR format, S3 naming conventions, dependency existence). If the data violates the schema, it is rejected immediately, preventing corruption of the state.
C. The Persistent State Store (Source of Truth)
- Component:
metadata/*.json - Role: The Database.
- Function: This is the immutable record of the infrastructure. Unlike typical scripts that "fire and forget," this system saves the user's intent. This allows for idempotency—running the tool multiple times produces the exact same result without duplication.
D. The Reconciliation Engine (The Generator)
- Component:
src/generator.py - Role: The Operator.
- Function: This component runs a continuous reconciliation loop.
- Watch: It reads the current configuration from the State Store.
- Diff: It determines which modules need to be created or updated.
- Act: It loads the appropriate Blueprints and renders the final Terraform code to the disk.
E. The Blueprint Store (Template Repository)
- Component:
templates/**/*.j2 - Role: The Spec Definitions.
- Function: These are logic-less, parameterized definitions of resources. They define the "Gold Standard" of how infrastructure should look. The Reconciliation Engine hydrates these blueprints with data from the State Store.
3. The Data Flow (The Lifecycle of a Request)
- Gateway: The User initiates a request via the Interface Gateway.
- Validation: The input is sent to the Admission Controller. If invalid, it returns an error.
- Persistence: Validated data is committed to the Persistent State Store.
- Trigger: The commit triggers the Reconciliation Engine.
- Render: The Engine pulls data from the State Store and schemas from the Blueprint Store.
- Output: The system writes the final artifacts (
.tffiles) to theroot/andterraform_modules/directories.
4. Key Architectural Principles
- Declarative Configuration: The system focuses on the desired end-state (stored in JSON), not the step-by-step commands to get there.
- Idempotency: You can run the generator 100 times; if the State Store hasn't changed, the output code remains consistent.
- Decoupled Logic: The templates (how code looks) are completely separated from the Python logic (how data is collected). This allows you to update Terraform versions in the templates without touching the Python codebase.
- Self-Healing Output: If a user accidentally deletes a generated
.tffile, running the generator again immediately restores it from the State Store.
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 simpleterraform-1.0.5.tar.gz.
File metadata
- Download URL: simpleterraform-1.0.5.tar.gz
- Upload date:
- Size: 35.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
691c4be959887be24f6d29c7df433e5eaacfeb8f43f597540c69c3f565495b0f
|
|
| MD5 |
470f6589bf7e577698263e66fbf17d91
|
|
| BLAKE2b-256 |
265e6d5de2e0226f2b45e73852a0b640ddf4992fb601e543347fc2ea0b493add
|
File details
Details for the file simpleterraform-1.0.5-py3-none-any.whl.
File metadata
- Download URL: simpleterraform-1.0.5-py3-none-any.whl
- Upload date:
- Size: 41.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
83b11ace0f445aa5b9777be3228c33a921b3cb9cb762e7a3663047efadd0f74f
|
|
| MD5 |
d8da247898ffb22503153f7145a7cac6
|
|
| BLAKE2b-256 |
5294a60eab0fe25ad00f880963db63d59754380e1c98c1c9e9b81f051fec66d7
|