How does Terraform resolve the version of a provider if the version is defined in both 'terraform' block and the 'provider' block?
Trap 1: The highest version wins.
Terraform does not compare the two constraints and pick the highest; the provider block's version argument is deprecated and ignored for resolution. The required_providers constraint in the terraform block determines which version is selected. Highest-version selection applies when a constraint range permits multiple releases.
Trap 2: The provider block takes precedence.
The provider block's version argument is deprecated and ignored; the required_providers constraint inside the terraform block controls which provider version Terraform installs. Provider blocks configure authentication and endpoints, not version resolution. Precedence by provider block applied in older Terraform versions before required_providers existed.
Trap 3: It causes a syntax error.
Terraform accepts a version constraint in the provider block and does not raise a syntax error; the terraform block's required_providers constraint governs resolution. Declaring versions in both places is valid but redundant. Syntax errors arise from malformed constraint operators, not from duplication.
- A
The highest version wins.
Why it fails: Terraform does not compare the two constraints and pick the highest; the provider block's version argument is deprecated and ignored for resolution. The required_providers constraint in the terraform block determines which version is selected. Highest-version selection applies when a constraint range permits multiple releases.
- B
The terraform block takes precedence.
Provider version constraints belong in the terraform block's required_providers; any version argument inside a provider block is ignored or errors. Terraform therefore honours the terraform block, satisfying the stem's conflict by resolving to that declaration.
- C
The provider block takes precedence.
Why it fails: The provider block's version argument is deprecated and ignored; the required_providers constraint inside the terraform block controls which provider version Terraform installs. Provider blocks configure authentication and endpoints, not version resolution. Precedence by provider block applied in older Terraform versions before required_providers existed.
- D
It causes a syntax error.
Why it fails: Terraform accepts a version constraint in the provider block and does not raise a syntax error; the terraform block's required_providers constraint governs resolution. Declaring versions in both places is valid but redundant. Syntax errors arise from malformed constraint operators, not from duplication.