Terraform 0.13+ deprecated specifying provider versions in the provider block. Move version constraints to the required_providers block in your terraform configuration to fix this warning.
This warning appears when you specify a provider version constraint using the `version` argument inside a provider configuration block. Terraform 0.13 introduced the `required_providers` block as the proper way to declare provider version constraints, and starting in Terraform 0.14, the old method was marked for deprecation. This change aligns with Terraform's dependency management system and enables the generation of `.terraform.lock.hcl` files for reproducible deployments.
Search your Terraform configuration for provider blocks that include a version argument. Here's the deprecated pattern:
provider "aws" {
version = "~> 5.0"
region = "us-east-1"
}In your root module's terraform block, add the required_providers section with the provider source and version constraint:
terraform {
required_version = ">= 1.0"
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
}Delete the version argument from all provider blocks. Keep only the provider-specific configuration:
provider "aws" {
region = "us-east-1"
}Execute terraform init in your working directory. This will:
- Download providers matching your version constraints
- Generate or update .terraform.lock.hcl with pinned versions
- Validate your configuration syntax
terraform initRun terraform plan or terraform validate to confirm the deprecation warning no longer appears:
terraform validate
# Expected output: Success! The configuration is valid.If your configuration uses multiple providers, add them all to the required_providers block:
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
azurerm = {
source = "hashicorp/azurerm"
version = "~> 3.0"
}
google = {
source = "hashicorp/google"
version = "~> 5.0"
}
}
}Add .terraform.lock.hcl to your version control system. This ensures all team members and CI/CD pipelines use the same provider versions:
git add .terraform.lock.hcl
git commit -m "Update provider version constraints"Dependency Lock File: Terraform 1.1+ automatically generates .terraform.lock.hcl when you run terraform init. This file pins the exact provider versions used, ensuring reproducible deployments across your team and CI/CD systems. Always commit this file to version control.
Version Constraint Operators: Use >= for minimum versions in reusable modules, ~> for patch updates (e.g., ~> 5.0 allows 5.0 to 5.999), and = for exact versions in production.
Provider Source Addresses: The source argument specifies the provider's registry location. HashiCorp providers use hashicorp/provider-name, while community providers use namespace/provider-name. You can also use private registry addresses.
Terraform Block: The required_providers block must be inside the terraform block at the root module level. Child modules inherit these requirements from the root module.
Error: Error rendering template: template not found
How to fix "template not found" error in Terraform
Error: Error generating private key
How to fix 'Error generating private key' in Terraform
Error creating Kubernetes Service: field is immutable
How to fix "field is immutable" errors in Terraform
Error: Error creating local file: open: permission denied
How to fix "Error creating local file: permission denied" in Terraform
Error: line endings have changed from CRLF to LF
Line endings have changed from CRLF to LF in Terraform