Infrastructure as Code (Terraform/OpenTofu)
What are the key trade-offs of Infrastructure as Code (Terraform/OpenTofu)? When would you choose it vs alternatives?
Answers use simple, clear English.
Quick interview answer
Pros: Reviewable, repeatable environments. Cons: State drift; blast radius of bad apply.
Detailed answer
Pros: Reviewable, repeatable environments. Cons: State drift; blast radius of bad apply. Decision: pick when benefits outweigh operational cost. Core: Declare cloud resources in code; plan/apply with state. Modules, workspaces/envs, remote state locks. Idempotent infra changes reviewed in PR. Real-time example: PR shows terraform plan +2 aws_s3_bucket; apply on merge to infra main. Pros: Reviewable, repeatable environments. Cons: State drift; blast radius of bad apply. Common mistakes: Manual console changes causing drift; secrets in state. Best practices: Remote state + lock; policy as code (OPA); no drift culture. Audience level: Tech Lead.
Full explanation
Declare cloud resources in code; plan/apply with state. Modules, workspaces/envs, remote state locks. Idempotent infra changes reviewed in PR.
Real example & use case
PR shows terraform plan +2 aws_s3_bucket; apply on merge to infra main.
Pros & cons
Pros: Reviewable, repeatable environments. Cons: State drift; blast radius of bad apply.
Common mistakes
Manual console changes causing drift; secrets in state.
Best practices
Remote state + lock; policy as code (OPA); no drift culture.
Follow-up questions
- How would you test Infrastructure as Code (Terraform/OpenTofu)?
- What metrics prove Infrastructure as Code (Terraform/OpenTofu) is healthy in prod?
- How does Infrastructure as Code (Terraform/OpenTofu) change at 10× traffic?