Learn whether the Terraform binary version and provider versions must match each other in a single configuration. Get a clear understanding of version compatibility in Terraform.
Table of Contents
Question
The Terraform binary version and provider versions must match each other in a single configuration.
A. True
B. False
Answer
B. False
Explanation
The Terraform binary version and provider versions do not need to match each other in a single configuration. Terraform allows flexibility in versioning, enabling the use of different provider versions with a specific Terraform binary version.
Terraform uses version constraints to specify acceptable provider versions. These constraints can be defined in the provider block using the `version` argument. The `version` argument accepts a version constraint string, allowing you to specify a range of compatible provider versions.
For example:
“`hcl
terraform {
required_providers {
aws = {
source = “hashicorp/aws”
version = “~> 3.0”
}
}
}
“`
In this example, the AWS provider is constrained to versions greater than or equal to 3.0 but less than 4.0. This allows using any version within that range, regardless of the Terraform binary version.
Terraform also supports provider version locking using the `.terraform.lock.hcl` file. This file records the selected provider versions during `terraform init`, ensuring consistent provider versions across different machines and team members.
It’s important to note that while provider versions don’t need to match the Terraform binary version, compatibility issues may arise if there are significant differences between versions. Therefore, it’s recommended to use provider versions that are compatible with the Terraform version in use.
HashiCorp Certified: Terraform Associate certification exam practice question and answer (Q&A) dump with detail explanation and reference available free, helpful to pass the HashiCorp Certified: Terraform Associate exam and earn HashiCorp Certified: Terraform Associate certification.