Skip to content

required-providers

Reports a provider that a resource, data or provider block uses and that no required_providers entry of the module names, on the last such block of the provider, and a required_providers entry without a version. The built-in terraform provider is exempt, and override files do not count.

Without the declaration Terraform picks the source of the provider by the default for its name, and without a version it takes the newest, so two runs of the same code can use different providers and a new major version can break the module with no change in the code.

To fix, add the provider to required_providers with a source and a version constraint.

Reported
...
backend "s3" {}
required_providers {
aws = { source = "hashicorp/aws", version = "~> 5" }
gcp = { source = "hashicorp/google" }
}
}
resource "aws_instance" "a" {}
resource "gcp_thing" "b" {}
resource "azure_thing" "c" {}
resource "azure_thing" "d" {}
resource "terraform_data" "e" {}
hcl:
lint:
rules:
required-providers: warn # off (default), warn, error

Enabled by the presets: hcl/tflint-recommended.

Suppress one line with sudsy-disable-next-line required-providers in a comment of the file’s language.

The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.

Tool Rule Match What differs
tflint terraform_required_providers partial Does not check each provider used for a source and a version, which needs the resources of the other files of the module.