Two engineers get different provider versions and see different plans for the same code. How do you stop this?
BeginnerScenarioWorkflow and Providers
Answer
Situation read → Provider versions are floating and nobody is committing the dependency lock file.
What I'd do →
- Declare constraints in
required_providers. - Commit
.terraform.lock.hclto Git. - Upgrade deliberately with
terraform init -upgradein a dedicated PR.
terraform {
required_version = ">= 1.9.0, < 2.0.0"
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.80"
}
}
}
Why → Constraints define the allowed range; the lock file pins the exact version and its checksums, so every machine and CI run uses identical providers.
Interview tip → "Constraint says what is allowed, lock file says what is used."
More on Workflow and Providers
A new teammate is about to run Terraform for the first time against a shared dev account. Which commands do you walk them through, and in what order?BeginnerYour manager asks why we bother with `terraform plan` when `apply` shows the same diff before asking for confirmation. What do you say?BeginnerSomeone committed the `.terraform/` directory to the repo. What should be in version control and what should not?BeginnerThe same configuration must create a VPC in `us-east-1` and a DR copy of a bucket in `eu-west-1`. How do you do it with one root module?IntermediateYou must deploy the same stack into 12 AWS accounts. How do you handle credentials and provider configuration?IntermediateHow do you make sure nobody runs your code with a Terraform version it wasn't tested against?Beginner