🧭 Key Discussion Points
-
Terraform Introduction
- What is Terraform?
- Use cases in cloud automation
-
HashiCorp Configuration Language (HCL)
- Syntax overview
- Declarative structure
-
Installation & Setup
- Download binary Terraform 1.13.1 Windows Binary
- Verify installation
-
Benefits & Cons of Terraform
- Pros: modularity, scalability
- Cons: state file complexity
-
AWS CLI Integration
- Install AWS CLI AWS CLI Installation Guide
- Configure credentials
-
Understanding IaC
- What is Infrastructure as Code?
- Why it matters in DevOps
-
Terraform ↔ AWS Connectivity
- Provider configuration
- Authentication via access keys
-
Practical Demo
- Created IAM user and group
- Attached policy for programmatic access
- Configured AWS CLI with credentials
- Used commands: terraform init, terraform plan, terraform apply
- Created EC2 instance using Terraform ▸ Used AMI image and named it Devmachine
- Validated Terraform configuration ▸ Used terraform validate to check syntax and logical consistency ▸ Optional: used JSON output for CI/CD integration
✅ Commands And process
- Download the Repo from cloud using https://github.com/WizardBrew/terraformcode
- open Git Bash or CMD
- step 1: terraform init
- Initializes the working directory
- Downloads provider plugins & Sets up backend configuration
- Prepares .terraform folder if first-time setup or after changing providers/backends
& lockes the .teraform file (no changes can be made) - step 2: terraform Plan
- Creates an execution plan (dry run)
- Reads current state
- Compares with desired state in .tf files
- Shows proposed changes Before applying changes to preview impact
- step 3: terraform apply
- Applies the changes to infrastructure
- Executes the plan, & - Provisions resources, then - Updates state file
- When you're ready to make changes live
- step 4: terraform Validate
- Verifies that your .tf files follow proper HCL (HashiCorp Configuration Language) syntax
- Runs in the current working directory and checks all loaded modules
- But Does not connect to cloud providers or check actual resource existence
- step 5: terraform destroy
- Destroys all resources defined in your Terraform configuration
- Everything tracked in the current state file (e.g., VMs, databases, networks)
- Updates the state file to reflect that resources no longer exist (Note to undo re run terraform apply and recreate all)
🚀 Workflow Commands
| Command | Explanation |
|---|---|
| terraform init | Initializes working directory, downloads providers/modules. |
| terraform plan | Previews changes without applying. |
| terraform plan -out=plan.tfplan | Saves plan to file for later apply. |
| terraform apply | Applies changes interactively. |
| terraform apply -auto-approve | Applies without confirmation (CI/CD use). |
| terraform destroy | Destroys all managed infra. Use carefully. |
| terraform destroy -target=aws_instance.web | Destroys only a specific resource. |
🛠 Validation & Formatting
| Command | Explanation |
|---|---|
| terraform validate | Checks `.tf` files for syntax/config errors. |
| terraform fmt | Formats `.tf` files into canonical HCL style. |
| terraform fmt -check | Checks formatting only (CI-friendly). |
| terraform fmt -recursive | Formats files in subdirectories too. |
📦 State Management
| Command | Explanation |
|---|---|
| terraform state list | Lists all resources tracked in state. |
| terraform state show <resource> | Shows attributes of a resource. |
| terraform state mv <src> <dst> | Moves/renames resource in state. |
| terraform state rm <resource> | Removes resource from state (infra stays). |
| terraform state pull | Downloads remote state as JSON. |
| terraform state push <file> | Uploads local state file to backend. |
| terraform import <resource> <id> | Imports existing infra into state. |
| terraform force-unlock <lock-id> | Releases a stuck state lock. |
🌍 Workspaces
| Command | Explanation |
|---|---|
| terraform workspace list | Lists all workspaces (dev, staging, prod). |
| terraform workspace show | Shows current workspace. |
| terraform workspace new <name> | Creates new workspace for environment separation. |
| terraform workspace select <name> | Switches workspace. |
| terraform workspace delete <name> | Deletes a workspace (not current). |
🔍 Inspection & Debugging
| Command | Explanation |
|---|---|
| terraform show | Displays current state or saved plan. |
| terraform show plan.tfplan | Shows saved plan file. |
| terraform output | Lists all output values. |
| terraform output -json | Outputs values as JSON. |
| terraform graph | dot -Tpng > graph.png | Generates dependency graph. |
| terraform providers | Lists required providers. |
| terraform version | Shows installed version. |
⚠️ Best Practices
- Always run
terraform planbeforeapply. - Use workspaces for environment separation.
- Keep state files secure (they contain secrets).
- Use remote backends (S3, Azure Blob, GCS) for collaboration.
- Apply
terraform fmt&terraform validatein CI/CD pipelines.
✅ Action Items
- Share Terraform setup scripts
- Document IAM policy steps
- Publish AWS CLI + Terraform guide
- verify the installation in cmd