Interview Prep/Terraform/Workflow and Providers

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 →

  1. Declare constraints in required_providers.
  2. Commit .terraform.lock.hcl to Git.
  3. Upgrade deliberately with terraform init -upgrade in 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."

All Terraform questions Roadmap: Terraform

More on Workflow and Providers