https://github.com/suraj-kumar00/terraform
Terraform best practices
https://github.com/suraj-kumar00/terraform
aws cloud devops infrastructure-as-code terraform terraform-aws terraform-cloud terraform-module
Last synced: 2 days ago
JSON representation
Terraform best practices
- Host: GitHub
- URL: https://github.com/suraj-kumar00/terraform
- Owner: Suraj-kumar00
- Created: 2025-07-10T18:15:34.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2025-10-03T18:13:04.000Z (6 months ago)
- Last Synced: 2025-10-03T20:22:56.738Z (6 months ago)
- Topics: aws, cloud, devops, infrastructure-as-code, terraform, terraform-aws, terraform-cloud, terraform-module
- Language: HCL
- Homepage:
- Size: 18.6 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Production Ready Terraform Configuration for AWS
Multi-environment infrastructure as code for AWS with modular, reusable Terraform configurations supporting development, staging, and production workloads.
---
## 📁 Project Structure
```
terraform/
├── environments/
│ ├── dev/ # Development environment
│ ├── staging/ # Staging environment
│ └── prod/ # Production environment
└── modules/
├── common/ # Shared resources
├── ec2/ # EC2 instances & security groups
├── ecr/ # Elastic Container Registry
├── eks/ # Elastic Kubernetes Service
├── iam/ # IAM roles & policies
├── keypair/ # SSH key management
├── s3/ # S3 storage buckets
└── vpc/ # Network infrastructure
```
---
## 🔧 Prerequisites
- [Terraform](https://www.terraform.io/downloads) v1.0+
- [AWS CLI](https://aws.amazon.com/cli/) configured with appropriate credentials
- AWS account with necessary permissions
---
## 🏗️ Modules
| Module | Description |
|--------|-------------|
| **common** | Shared resources and configurations |
| **ec2** | Instance and security group management |
| **ecr** | Elastic Container Registry for Docker images |
| **eks** | Elastic Kubernetes Service cluster management |
| **iam** | Identity and Access Management roles/policies |
| **keypair** | SSH key pair management |
| **s3** | Storage bucket with security features |
| **vpc** | Network infrastructure and routing |
---
## 🌍 Environment Specifications
| Environment | Instance Type | CIDR Block | Purpose |
|-------------|--------------|------------|---------|
| **dev** | t2.micro | 10.0.0.0/16 | Feature development & testing |
| **staging** | t2.small | 10.1.0.0/16 | Pre-production testing |
| **prod** | t2.medium | 10.2.0.0/16 | Live workloads |
---
## 🚀 Quick Start
```bash
# 1. Navigate to environment
cd environments/ # dev, staging, or prod
# 2. Initialize Terraform
terraform init
# 3. Review changes
terraform plan
# 4. Apply infrastructure
terraform apply
```
---
## 🔑 Key Features
### Infrastructure Components
- VPC with public/private subnets
- EC2 instances for web and application servers
- EKS clusters for container orchestration
- ECR repositories for Docker images
- S3 buckets for storage
- IAM roles and policies
### Security Measures
- Network isolation with security groups
- IAM role-based access control
- Encryption at rest
- Public access blocking
- Least privilege principle
### Scalability
- Environment-specific resource sizing
- Modular, reusable design
- Expandable CIDR ranges
---
## 📋 Common Commands
| Command | Description |
|---------|-------------|
| `terraform init` | Initialize working directory |
| `terraform plan` | Preview infrastructure changes |
| `terraform apply` | Create/update infrastructure |
| `terraform destroy` | Destroy all resources |
| `terraform destroy -target=TYPE.NAME` | Destroy specific resource |
> ⚠️ **Warning**: Avoid using `terraform destroy --auto-approve` in production environments.
---
## ✅ Best Practices
### Code Organization
- Modular structure with DRY principles
- Clear separation of concerns
- Environment isolation
### Security
- Network segmentation
- Resource isolation
- Access controls with encryption
### Maintainability
- Consistent naming conventions
- Environment-specific state files
- Remote backend for production