Q: How do you handle provider version pinning in Terraform?
In versions.tf:
#Terraform #Workspaces & CI/CD #L2 #IaC #Cloud Infrastructure
🎙️ Candidate Opening & Architectural Context
""In our enterprise Terraform repository, we designed reusable modules and remote backends to prevent this exact issue. When addressing this question, I walk the interviewer through our production incident runbook: isolating the blast radius, checking diagnostic logs and metrics, and applying a safe fix.""
Advertisement
🛠️ Production Runbook & Step-by-Step Resolution
1️⃣
Production Solution & Architecture
In versions.tf: Then run terraform init and commit the .terraform.lock.hcl file. This file locks the exact provider version for all team members and CI. Why pin: provider upgrades can introduce breaking changes. ~> 5.0 is a safe constraint — allows patch updates but not major changes. Never use >= 3.0 without an upper bound — you could suddenly get a breaking major version update. --- ## 🟠 Security & Best Practices
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0" # allows 5.x, not 6.x
}
}
required_version = ">= 1.5.0"
}
💡 The Senior SRE Gold Nugget (Key Architectural Takeaway)
"Pro-Tip: In versions.tf:."
⚡ 60-Second Elevator Pitch Talking Points
- Immediate Triage: In versions.tf:
- Run targeted verification commands before modifying configuration.
- Automate permanent guardrails (CI check, alerts, IaC policy) to prevent recurrence.
Advertisement