by M Inamdar
π Hey there! Iβm Mustkhim Inamdar, a Cloud-Native DevOps Architect passionate about automation, scalability, and next-gen tooling. With 9+ years of experience across Big Data, Cloud Operations (AWS), CI/CD, and DevOps for automotive systems, Iβve delivered robust solutions using tools like Terraform, Jenkins, Kubernetes, LDRA, Polyspace, MATLAB/Simulink, and more.
I love exploring emerging tech like GitOps, MLOps, and GenAI, and sharing practical insights from real-world projects. Letβs dive into the world of DevOps, cloud, and automation together!
Modern cloud infrastructure demands automation, scalability, and maintainability and thatβs exactly where Infrastructure as Code (IaC) shines. But as your infrastructure grows, maintaining hundreds of lines of Terraform in a single file becomes chaotic.
That's why I built this:
A clean, modular, and production-grade Terraform repository that can deploy scalable AWS infrastructure across multiple environments.
This article is a deep dive into the repo:
iac-aws-modular-infra
Why This Project Exists
Most Terraform tutorials and starter templates are overly simple or donβt reflect real-world complexity. This project is built for engineers and teams who need:
- β Modular, reusable infrastructure components
- β Multi-environment separation (e.g., dev, prod)
- β Remote state management
- β Cleaner code structure and CI/CD-ready setup
- β A launchpad for integrating EKS, RDS, etc.
This repo follows the best practices recommended by HashiCorp and the Terraform community.
Whatβs Inside the Repo?
This Terraform repo includes the following modular AWS resources:
Module | Description |
---|---|
vpc |
Creates custom VPCs, subnets, route tables, IGW, etc. |
ec2 |
Deploys EC2 instances inside public/private subnets |
s3 |
Creates S3 buckets with custom configuration |
sg |
Custom security groups for EC2, load balancers, etc. |
iam |
IAM roles and policies (basic version included) |
cloudwatch |
Adds alarms and monitoring for EC2 or custom metrics |
Directory Layout
iac-aws-modular-infra/
β
βββ backend/ # Remote state config using S3
β βββ s3_backend.tf
β
βββ environments/ # Separated environments
β βββ dev/
β β βββ main.tf
β βββ prod/
β
βββ modules/ # All infrastructure modules
β βββ vpc/
β βββ ec2/
β βββ s3/
β βββ sg/
β βββ iam/
β βββ cloudwatch/
β
βββ README.md
How to Deploy
1. Clone the Repo
Clone the infrastructure code to your local machine and navigate to the desired environment (e.g., dev
).
git clone https://github.com/M-Inamdar/iac-aws-modular-infra.git
cd iac-aws-modular-infra/environments/dev
2. Create terraform.tfvars
Define environment-specific values for input variables. This file keeps your configuration modular and reusable.
region = "ap-south-1"
vpc_cidr_block = "10.0.0.0/16"
public_subnet_cidrs = ["10.0.1.0/24"]
private_subnet_cidrs = ["10.0.2.0/24"]
instance_type = "t2.micro"
ami_id = "ami-0abcdef1234567890"
Tip: Add this file to
.gitignore
to avoid committing sensitive or environment-specific data.
3. Initialize Terraform
Set up the working directory and download the required provider plugins and modules.
terraform init
4. Plan & Apply
Preview the changes with plan
and then provision the infrastructure using apply
.
terraform plan
terraform apply
β Youβll be prompted to confirm before resources are created.
5. Optional: Destroy Infrastructure
Use this to tear down all provisioned resources if no longer needed.
terraform destroy
Caution: This will remove all resources. Double-check before running.
Remote State Management
Terraform uses an S3 bucket to manage state centrally for team collaboration and history tracking.
Example backend config in backend/s3_backend.tf
:
terraform {
backend "s3" {
bucket = "my-terraform-state"
key = "dev/terraform.tfstate"
region = "ap-south-1"
}
}
Tip: Enable DynamoDB state locking to avoid concurrent apply conflicts:
dynamodb_table = "terraform-locks"
Additional Suggestions
-
Modular Code: Reuse modules from the
modules/
directory across different environments (e.g., dev, staging, prod). - Secrets Management: Avoid hardcoding credentials. Use environment variables or tools like AWS Secrets Manager or SSM Parameter Store.
-
Validation: Run
terraform validate
before applying to catch config errors. - Automation: Integrate with CI/CD pipelines (e.g., GitHub Actions, Jenkins) for consistent deployment.
- Documentation: Maintain a README per environment or module for clarity.
Design Philosophy
βInfrastructure should be treated as code and that code should be clean, reusable, and easy to test.β
I designed this repo with the following principles:
β
Modularity: Each AWS resource lives in its own module
β
Reusability: Modules can be called from any environment
β
Clarity: Variables and outputs are explicitly defined
β
Separation of concerns: Code for prod/dev stays isolated
β
Cloud-readiness: Backend is set up for remote storage
Whatβs Next?
Hereβs what Iβm planning to add next:
- Terraform GitHub Actions for CI/CD
- Cost estimates with Infracost
- State locking via DynamoDB
- Terratest-based module unit tests
- EKS-ready VPC modules
TL;DR
- Modular Terraform setup β
- Real-world AWS patterns β
- Remote state and multi-env support β
- Ready for scaling and CI/CD β
π€ Contributing
Feel free to fork the repo, raise issues, or open pull requests. Feedback and contributions are always welcome!
If you use this in your projects, Iβd love to hear about it drop a comment or star β the repo iac-aws-modular-infra
Happy automating!
π¬ Got questions or stuck somewhere?
Feel free to drop a comment below or DM me on LinkedIn.
Iβm always happy to help!
Top comments (2)
this is super clean and i wish i had it in my early devops days tbh you think modular setups ever get too complex for their own good
Thanks a lot!
And yep, totally modular setups can get messy if overdone. Balance is key: reusable but not over nested. Appreciate you stopping by.