4.2 KiB
4.2 KiB
Terraform Instruction Lab – From Zero to Team Collaboration (2 Hours)
This hands-on lab takes you from first contact with Terraform to a safe, team-ready workflow on AWS. You will provision real infrastructure, structure your code with variables and modules, and protect your state with an S3 backend and DynamoDB state locking. The material is paced for beginners and practical for engineers who want a concise, end‑to‑end setup they can reuse at work.
Audience: Beginners using Ubuntu 24 for the first time
Goal: Deploy AWS resources using Terraform, adopt variables/outputs and modules, and enable remote state + locking for collaboration.
Outcomes
- Understand what Terraform is and how it manages infrastructure as code (IaC)
- Install and verify Terraform + AWS CLI on Ubuntu 24
- Authenticate to AWS and validate IAM access
- Write a minimal Terraform configuration and deploy an EC2 instance
- Introduce variables, tfvars, and outputs for reuse and clarity
- Configure remote state in S3 with DynamoDB locking to prevent race conditions
- Compose and reuse modules (including a simple nested VPC + EC2 example)
- Clean up all resources to avoid unnecessary AWS costs
What We’ll Build
- A small, cost-conscious AWS stack:
- Optional VPC with public subnet and Internet gateway
- A single EC2 instance (Free Tier eligible type where possible)
- Remote Terraform state stored in S3 with DynamoDB table for locking
- A reusable module layout you can extend for real projects
Prerequisites
- AWS account (Free Tier is fine) and basic familiarity with regions
- IAM user or role with permissions for EC2, S3, and DynamoDB
- Ubuntu 24.04 machine (VM, physical, or WSL) with Internet access
- Willingness to use the terminal (copy/paste is fine!)
Tip: New to AWS CLI? No problem—setup is guided and verified in this lab.
Lab Roadmap
docs/01_install_setup.md: Install Terraform + AWS CLI and verify environmentdocs/02_first_ec2.md: Author your first Terraform config and deploy EC2docs/03_remote_state_s3_dynamodb.md: Configure S3 backend and DynamoDB lockingdocs/04_variables_tfvars_outputs.md: Introduce variables, tfvars, and outputsdocs/05_modules_reuse.md: Create and consume modules; structure for reusedocs/06_nested_modules_vpc_ec2.md: Model a simple VPC + EC2 with nested modulesdocs/07_cleanup.md: Destroy resources and verify nothing is left behinddocs/08_test.md: Optional checks and validation ideas
Estimated Time (2 Hours)
- Setup and verification: 15–20 min
- First EC2 with basics: 15–20 min
- Remote state + locking: 20–25 min
- Variables, tfvars, outputs: 15–20 min
- Modules + nested example: 25–30 min
- Cleanup and wrap‑up: 10 min
Key Concepts
- Declarative IaC: Describe desired state; Terraform plans and applies changes
- State: Terraform tracks real resources; protect it with remote storage + locks
- Idempotence: Re‑runs converge to the same outcome when code is unchanged
- Modules: Encapsulate patterns, promote reuse and reviewability
- Collaboration: S3 state + DynamoDB locks prevent conflicting applies
Safety, Cost, and Region
- Choose a region close to you and consistent across the lab (e.g.,
us-east-1) - Prefer Free Tier eligible instance types (e.g.,
t2.microort3.micro) - Always run the cleanup step in
docs/07_cleanup.mdafter experimenting - Remote state resources (S3 bucket, DynamoDB table) have minimal ongoing cost
Tools You’ll Use
- Terraform CLI (1.6+ recommended)
- AWS CLI v2
- A text editor and terminal (bash/zsh)
Deliverables
- A working Terraform project that can:
- Deploy a basic EC2 instance (optionally inside a simple VPC)
- Output connection details
- Store state in S3 with DynamoDB locking for team safety
- A module structure you can clone for future services
Troubleshooting and Help
- Use
terraform init -upgradeif providers appear outdated - Validate AWS credentials with
aws sts get-caller-identity - Run
terraform planto preview changes before apply - If a lock persists, check and clear it via the DynamoDB console (only if safe)
- See
docs/08_test.mdfor additional verification ideas
When you’re ready, start with installation in docs/01_install_setup.md.