This repository contains a modular Infrastructure as Code (IaC) setup using Terraform. It provisions a clean, segregated AWS environment using custom modules and community modules.
The repository is logically divided into reusable modules and distinct environments:
modules/: Contains reusable templates.vpc: Wraps the official Terraform AWS VPC module to spin up secure networks across availability zones.iam: Provisions IAM Users, automatically adds them to shared IAM Groups, sets up passwords, and attaches policies.ec2: Fetches the latest Amazon Linux 2023 AMI dynamically and deploys an EC2 instance into our VPC.
environments/: Contains environment-specific configurations that consume the modules.dev: Configuration isolated for development traffic.prod: Configuration isolated for production traffic.
- Terraform >= 1.0.0
- An AWS Account
- Clone this repository down to your local machine.
- Navigate to your desired environment (e.g.,
cd environments/dev). - Create a backend configuration or variables file. We use
terraform.tfvars. Because this file often contains sensitive access keys, it is ignored by Git by default. Create aterraform.tfvarsvisually similar to this:aws_region = "us-east-1" aws_access_key = "YOUR_AWS_ACCESS_KEY" aws_secret_key = "YOUR_AWS_SECRET_KEY"
Use the standard Terraform workflow to launch the environment:
# 1. Initialize the provider and remote modules
terraform init
# 2. Validate syntactic correctness
terraform validate
# 3. Preview your infrastructure before deployment
terraform plan
# 4. Deploy!
terraform applyTo clean up and avoid AWS charges:
terraform destroyThe .gitignore has been strictly formatted to ignore terraform.tfstate files, .terraform caching directories, and *.tfvars variable inputs to maintain a secure repository cleanly. Never commit your IAM access and secret keys.