TA-002-P · Question #85
You need to constrain the GitHub provider to version 2.1 or greater. Which of the following should you put into the Terraform 0.12 configuration's provider block?
The correct answer is D. version = ">= 2.1". To constrain a provider to version 2.1 or greater in a Terraform 0.12 configuration, the correct version constraint syntax using the greater-than-or-equal-to operator is version = ">= 2.1". This ensures that only versions equal to or newer than 2.1 are used.
Question
You need to constrain the GitHub provider to version 2.1 or greater. Which of the following should you put into the Terraform 0.12 configuration's provider block?
Options
- Aversion >= 2.1
- Bversion ~> 2.1
- Cversion = "<= 2.1"
- Dversion = ">= 2.1"
How the community answered
(17 responses)- A6% (1)
- B6% (1)
- D88% (15)
Why each option
To constrain a provider to version 2.1 or greater in a Terraform 0.12 configuration, the correct version constraint syntax using the greater-than-or-equal-to operator is `version = ">= 2.1"`. This ensures that only versions equal to or newer than 2.1 are used.
The syntax `version >= 2.1` is incomplete; it needs to be assigned as `version = ">= 2.1"`.
The pessimistic constraint `~> 2.1` means `version >= 2.1.0` and `version < 2.2.0`, which does not allow versions like 2.2.0 or 3.0.0, thus not fulfilling the condition of "2.1 or greater" in a general sense.
`version = "<= 2.1"` specifies "version 2.1 or less", which is the opposite of what is required.
To specify a minimum version constraint of "2.1 or greater" for a provider in Terraform, the correct syntax within the `required_providers` block (or `provider` block in older Terraform 0.12) is `version = ">= 2.1"`. This allows Terraform to use any patch, minor, or major version equal to or above 2.1.
Concept tested: Terraform provider version constraints
Source: https://developer.hashicorp.com/terraform/language/expressions/version-constraints
Topics
Community Discussion
No community discussion yet for this question.