TFNFR26 - Providers in required_providers
The terraform
block in terraform.tf
MUST contain the required_providers
block.
Each provider used directly in the module MUST be specified with the source
and version
properties. Providers in the required_providers
block SHOULD be sorted in alphabetical order.
Do not add providers to the required_providers
block that are not directly required by this module. If submodules are used then each submodule SHOULD have its own versions.tf
file.
The source
property MUST be in the format of namespace/name
. If this is not explicitly specified, it can cause failure.
The version
property MUST include a constraint on the minimum version of the provider. Older provider versions may not work as expected.
The version
property MUST include a constraint on the maximum major version. A provider major version release may introduce breaking change, so updates to the major version constraint for a provider MUST be tested.
The version
property constraint SHOULD use the ~> #.#
or the >= #.#.#, < #.#.#
format.
Note: You can read more about Terraform version constraints in the documentation .
Good examples:
terraform {
required_version = "~> 1.6"
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~> 3.0"
}
}
}
terraform {
required_version = ">= 1.6.6, < 2.0.0"
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = ">= 3.11.1, < 4.0.0"
}
}
}
terraform {
required_version = ">= 1.6, < 2.0"
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = ">= 3.11, < 4.0"
}
}
}
Acceptable example (but not recommended):
terraform {
required_version = "1.6"
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "3.11"
}
}
}
Bad example:
terraform {
required_version = ">= 1.6"
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = ">= 3.11"
}
}
}