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-1git 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!
