nerdexam
HashiCorp

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.

Read, generate, and modify configuration

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)
  • A
    6% (1)
  • B
    6% (1)
  • D
    88% (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.

Aversion >= 2.1

The syntax `version >= 2.1` is incomplete; it needs to be assigned as `version = ">= 2.1"`.

Bversion ~> 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.

Cversion = "<= 2.1"

`version = "<= 2.1"` specifies "version 2.1 or less", which is the opposite of what is required.

Dversion = ">= 2.1"Correct

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

#Terraform providers#Version constraints#HCL syntax#Configuration

Community Discussion

No community discussion yet for this question.

Full TA-002-P Practice