A beginner-friendly guide to setting up AWS infrastructure using Terraform! Learn how to automate and manage cloud resources with ease.
✅ Deploy AWS Resources using Terraform
✅ Manage Infrastructure as Code (IaC)
✅ Use Remote State Storage with S3 + DynamoDB
✅ Create VPC, Subnets, and EC2 Instances
✅ Configure Security Groups and Networking
✅ Apply Best Practices for Terraform Code Structure
AWS-Terraform-Workshop/
│── scripts/ # Shell scripts for user data and setup
│ └── user_data.sh # Bootstrap script for EC2 instances
│── main.tf # Main Terraform configuration (VPC, EC2, networking)
│── variables.tf # Input values for easy customization
│── outputs.tf # Output values of deployed resources
│── backend.tf # Remote state setup (S3 + DynamoDB)
│── backend-variables.tf # Variables for backend configuration
│── provider.tf # AWS provider configuration
│── terraform.tfvars.example # Example variable values
│── README.md # This guide! 📖
🔹 Download Terraform (v1.0.0 or newer) 🔹 Install AWS CLI and set up credentials using:
aws configure
🔹 Create an S3 bucket & DynamoDB table for storing Terraform state:
# Create S3 bucket
aws s3 mb s3://your-terraform-state-bucket --region us-east-1
# Create DynamoDB table (with 'LockID' as partition key)
aws dynamodb create-table \
--table-name your-terraform-lock-table \
--attribute-definitions AttributeName=LockID,AttributeType=S \
--key-schema AttributeName=LockID,KeyType=HASH \
--billing-mode PAY_PER_REQUEST \
--region us-east-1
git clone https://github.com/NotHarshhaa/AWS-Terraform-Workshop.git
cd AWS-Terraform-Workshop
# Create a tfvars file with your specific values
cp terraform.tfvars.example terraform.tfvars
# Edit the terraform.tfvars file with your preferred editor
# Basic initialization
terraform init
# Or with custom backend configuration
terraform init \
-backend-config="bucket=your-terraform-state-bucket" \
-backend-config="dynamodb_table=your-terraform-lock-table" \
-backend-config="region=us-east-1"
👉 This sets up Terraform by downloading necessary plugins and configuring remote state.
# Preview changes
terraform plan -out=tfplan
# Apply the saved plan
terraform apply tfplan
# Or directly apply (will prompt for confirmation)
terraform apply
⚡ This will create a complete infrastructure including:
- VPC with proper CIDR blocks
- Public subnet with internet connectivity
- Security groups with configurable ports
- EC2 instance with Apache web server
# View all the output values
terraform output
# Get a specific output value (e.g., web server URL)
terraform output web_url
# SSH to your instance
terraform output ssh_connection_string
# Then modify the command with the actual path to your key file
# Preview what will be destroyed
terraform plan -destroy
# Destroy all resources
terraform destroy
⛔ This will delete all deployed AWS resources.
🔹 Always use Remote State – Store Terraform state in S3 to prevent conflicts.
🔹 Use Variables and Outputs – Parameterize your code for flexibility.
🔹 Separate User Data Scripts – Keep bootstrap scripts in separate files.
🔹 Apply Proper Tagging – Tag resources consistently for better management.
🔹 Use Dynamic Blocks – For repeatable resource configurations.
🔹 Check Plan Before Applying – Always run terraform plan
first!
🔹 Security First – Restrict security group rules to minimum required access.
🔹 Found something to improve? Open a pull request!
🔹 Have questions? Feel free to open an issue!
🔹 Want to extend? Add more resources like RDS, S3, or Lambda!
📝 This project is licensed under MIT License – Free to use and modify!
🔹 Terraform Documentation 🔹 AWS Provider Documentation 🔹 Terraform Best Practices
🚀 Happy Terraforming! 🌍
If you find this repository helpful and plan to use it for learning, please consider giving it a star ⭐. Your support motivates me to keep improving and adding more valuable content! 🚀
This project is crafted with passion by Harshhaa 💡.
I’d love to hear your feedback! Feel free to open an issue, suggest improvements, or just drop by for a discussion. Let’s build a strong DevOps community together!
Stay connected and explore more DevOps content with me:
Want to stay up to date with the latest DevOps trends, best practices, and project updates? Follow me on my blogs and social channels!