Terraform provider requirements accept const variables and locals
Introduced 2026-10-21 · score 0.97
HOW TO USE IT
When provider source or version requirements need values supplied as constants or locals, reference them in `required_providers`; keep variable values independent of dynamic plan results. Supply const-variable values at plan time with supported methods such as `-var`, `-var-file`, or environment variables.
terraform {
required_providers {
random = {
source = "app.terraform.io/${var.organization}/random"
version = local.random_version
}
}
}
variable "organization" {
type = string
const = true
}
locals {
random_version = "3.9.0"
}terraform initWHY THIS HELPS
Configure provider requirements with organization or version values supplied as constants or locals.
REQUIREMENTS AND LIMITATIONS
- Version: 1.17.0
- required_providers.<LOCAL_NAME>.source (required): Provider source address; may reference a const variable.
- required_providers.<LOCAL_NAME>.version: Provider version constraint; may reference a const variable or local.
- variable.<NAME>.const: Set to `true` for an input variable used in provider requirements.
- -var=<NAME>=<VALUE>: Set an input variable value on the command line.
- -var-file=<FILE>: Load input variable values from a file.
- TF_VAR_<NAME>: Set an input variable through an environment variable.
- Prerequisite: Terraform v1.17.0 or later is required for the feature described in the release note.
- Prerequisite: Variables used in provider requirements must be declared `const = true`; provide their values using a method supported during plan.
- Prerequisite: Values cannot depend on dynamic results from a plan step.
- Values can't depend on any dynamic results from a plan step.
FIRST-PARTY EVIDENCE
- https://github.com/hashicorp/terraform/releases/tag/v1.17.0
- https://github.com/hashicorp/terraform/pull/39153
- https://developer.hashicorp.com/terraform/cli/commands/init
- https://developer.hashicorp.com/terraform/language/providers/requirements
- https://developer.hashicorp.com/terraform/cli/commands/plan
- https://developer.hashicorp.com/terraform/language/values/variables
Check the installed version and the source before using it. Entry JSON