terraform Interview Questions: ============================== 1).Terraform Practical Interview Questions (Experienced) 1. Real-time Scenario Questions 👉 Q1: You have created infrastructure manually in AWS. Now you need to bring it under Terraform. How will you do it? Expected Answer: Use terraform import Write resource block first Import using: terraform import aws_instance.myec2 i-1234567890 Run terraform plan to verify 👉 Q2: You deleted a resource manually in AWS, but Terraform state still has it. What will you do? Answer: Run: terraform refresh OR terraform apply Terraform will recreate the resource 👉 Q3: How will you handle multiple environments (dev, qa, prod)? Answer: Use: Workspaces Separate backend configs .tfvars files Example: terraform workspace new dev terraform workspace select dev 👉 Q4: How do you manage secrets in Terraform? Answer: Use: AWS Secrets Manager HashiCorp Vault Environment variables Avoid hardcoding in .tf files 👉 Q5: How do you handle remote state? Answer: Use S3 backend + DynamoDB locking backend "s3" { bucket = "my-terraform-state" key = "prod/terraform.tfstate" region = "us-east-1" dynamodb_table = "terraform-lock" } 2. Debugging & Troubleshooting 👉 Q6: Terraform apply failed in middle. What happens? Answer: State file updates partially Next apply will continue from failed point 👉 Q7: How do you resolve state file corruption? Answer: Restore from backup Use remote backend (S3 versioning) 👉 Q8: How to remove resource from state without deleting it? terraform state rm aws_instance.myec2 👉 Q9: Difference between taint and replace? Answer: taint: mark resource for recreation replace: force recreation immediately 3. Code & Architecture Design 👉 Q10: How do you design reusable Terraform code? Answer: Use modules module "vpc" { source = "./modules/vpc" } 👉 Q11: How do you pass variables? Answer: CLI .tfvars Environment variables 👉 Q12: What is count vs for_each? Answer: count: index-based for_each: key-based (preferred for maps) 👉 Q13: How do you create dependencies? Answer: Implicit (reference) Explicit: depends_on = [aws_vpc.main] 4. CI/CD & Automation 👉 Q14: How do you integrate Terraform with CI/CD? Answer: Jenkins / GitHub Actions pipeline: terraform init terraform validate terraform plan Approval terraform apply 👉 Q15: How do you prevent accidental deletion? Answer: lifecycle { prevent_destroy = true } 5. Advanced Questions 👉 Q16: What is state locking and why needed? Answer: Prevents concurrent execution Done via DynamoDB (AWS) 👉 Q17: How do you manage large infrastructure? Answer: Split into modules Use multiple state files Use workspaces 👉 Q18: How do you upgrade Terraform safely? Answer: terraform init -upgrade Check provider compatibility 👉 Q19: How do you handle drift? Answer: terraform plan Detect changes outside Terraform 👉 Q20: How to rollback infrastructure? Answer: Use previous state file Version control (Git) 💡 Pro Tips (Interview Booster) Always mention: State management Modules Security (secrets) CI/CD Give real-time examples (AWS EC2, VPC, S3)

Comments

Popular posts from this blog

Linux interview Questions :

Linux interview questions