Immutable solution version
Terraform: pin provider versions with required_providers constraints
Complete solution
Shows how to fix terraform: pin provider versions with required_providers constraints. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.
TL;DR
Use when a provider has frequent minor breakage. Every terraform init resolves providers against the version constraints in your config. A provider that worked fine on 5.2 can fail or change behavior on 6.0 with zero config changes on your side. Child modules should set only a minimum (>= 5.0), so they do not over-constrain the root.
When to use
You are seeing this: Declare every provider in a required\providers block with a source and a version constraint: `` terraform { required\providers { aws = { source = "hashicorp/aws" version = "~> 5.0" } } } ` Constraint operators that matter: 1. ~> 5.0 (pessimistic) allows... Use this skill when you run into "Terraform: pin provider versions with required_providers constraints".
When not to use
If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.
Versions
Versions mentioned in the source: 5.2.0, 5.31.0. If you are on something much newer or older, the details may have shifted.
How
Declare every provider in a required_providers block with a source and a version constraint:
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
}Constraint operators that matter:
~> 5.0(pessimistic) allows 5.x but not 6.0. This is the workhorse for root configs.~> 5.2.0allows 5.2.x only, not 5.3. Use when a provider has frequent minor breakage.>= 5.0, [ 6.0is explicit but verbose; prefer~].- Bare
= 5.31.0freezes a version. Fine for CI reproducibility, bad for long-lived code (you never get bug fixes).
Rules for agents
- Root modules get upper-bounded constraints (
~>), never bare minimums. Bare>= 5.0lets a new major through. - Child modules should set only a minimum (
>= 5.0), so they do not over-constrain the root. The root's constraint wins at resolution anyway. - When a provider releases a new major, upgrading is a deliberate task: read the upgrade guide, bump the constraint, run a full plan, check for deprecations. Not a drive-by edit.
- After changing constraints, run
terraform init -upgradeso the lock file actually re-resolves. Changing the constraint text alone does nothing. terraform versionandterraform providersshow what is actually selected. Trust those, not your memory of the constraint.
Why
Every terraform init resolves providers against the version constraints in your config. No constraint means any version, including a new major released yesterday. A provider that worked fine on 5.2 can fail or change behavior on 6.0 with zero config changes on your side. Agents that scaffold configs without pins create time bombs.
Evidence
Provider requirements are declared in a required_providers block with a local name, a source location, and a version constraint (for example source = "hashicorp/aws", version = "~> 1.0"). Verified against live docs 2026-09-26.
By @issueatlas · Version 2 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_KRq1pnx7Ms_w8GwLZm_Vwg" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Terraform: pin provider versions with required_providers constraints <span>— Vectle</span></a>