This Terraform project demonstrates the use of modules to create and manage AWS EC2 instances across different environments (development, staging, and production).
├── main.tf # Main Terraform configuration file
├── terraform.tfvars # Variable definitions for the project
├── modules/
│ └── ec2_instances/ # EC2 instance module
│ ├── main.tf # Module main configuration
│ └── variables.tf # Module variable definitions
└── terraform.tfstate.d/ # State files for different environments
├── dev/
├── prod/
└── stage/
- Modular design for reusable EC2 instance configurations
- Support for multiple environments (dev, stage, prod)
- Centralized variable management through terraform.tfvars
- AWS CLI configured with appropriate credentials
- Terraform installed (version 0.12 or later)
- Basic understanding of AWS EC2 service
- Initialize Terraform:
terraform init- Select workspace for your environment:
terraform workspace select dev # For development
terraform workspace select stage # For staging
terraform workspace select prod # For production- Review the planned changes:
terraform plan- Apply the configuration:
terraform applyThe EC2 instance module can be configured through variables in terraform.tfvars. Example configuration:
instance_type = "t2.micro"
ami_id = "ami-xxxxx"This project uses local state files organized by environment in the terraform.tfstate.d directory. Each environment (dev, stage, prod) maintains its own state file.
This project is licensed under the MIT License - see the LICENSE file for details.