Terraform cannot find a referenced provider alias because it wasn't defined in your root module configuration. This error occurs when using aliased providers with modules without proper configuration passing.
Terraform allows you to create multiple configurations for the same provider using aliases. For example, you might have AWS providers for different regions like 'aws.us-east' and 'aws.eu-west'. This error occurs when you reference an alias that either doesn't exist, wasn't passed to a module correctly, or was removed from the configuration while resources still depend on it. The error typically happens in two scenarios: (1) A module references an aliased provider that isn't defined in the root module, or (2) You removed a provider configuration from your root module while resources created by that provider still exist in your Terraform state.
Check your root module (usually main.tf or providers.tf) to ensure all referenced aliases are actually defined.
Example of correct provider alias definition:
# Root module - main.tf
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
}
provider "aws" {
region = "us-east-1"
}
provider "aws" {
alias = "replica"
region = "us-west-2"
}If you're missing a provider alias definition that your configuration needs, add it to your root module.
If you're using modules with aliased providers, ensure you're passing providers explicitly to the module.
module "app_replica" {
source = "./modules/app"
# Explicitly pass the aliased provider to the module
providers = {
aws = aws.replica
}
}Without the providers argument, the module receives only the default provider configuration.
If you have a child module that uses aliased providers, declare them using configuration_aliases in the required_providers block.
# modules/app/main.tf
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
configuration_aliases = [aws.replica]
}
}
}
resource "aws_s3_bucket" "backup" {
provider = aws.replica
bucket = "my-backup-bucket"
}This tells Terraform and other developers that this module accepts an aliased provider.
If you removed a provider alias from your configuration but resources still reference it in state, you have two options:
Option 1: Temporarily restore the provider to destroy resources
# Restore the provider alias
provider "aws" {
alias = "old_region"
region = "deprecated-region"
}
# Resources will reference it, allowing terraform destroyThen run:
terraform destroy -target='aws_resource.name'Option 2: Manually remove from state (advanced)
terraform state rm 'aws_resource.name'This is a last resort if you cannot restore the provider configuration.
After making changes, validate that your configuration is correct:
terraform validateThis will catch issues like:
- Undefined provider aliases
- Incorrect module provider references
- Missing configuration_aliases declarations
If terraform validate succeeds, you can proceed with terraform plan.
Terraform version compatibility: Provider aliases have evolved across Terraform versions. In Terraform 0.13+, the configuration_aliases mechanism was introduced to better support modular configurations. If you're upgrading Terraform, review the changelog for provider-related changes.
Modules and for_each/count: Modules with provider configurations (instead of configuration_aliases) are incompatible with the for_each and count arguments. Always use configuration_aliases in reusable modules.
Provider source requirements: Ensure your required_providers block specifies the correct provider source and version constraints. Misconfigured sources can lead to provider resolution issues.
Error: Error installing helm release: cannot re-use a name that is still in use
How to fix "release name in use" error in Terraform with Helm
Error: Error creating GKE Cluster: BadRequest
BadRequest error creating GKE cluster in Terraform
Error: External program failed to produce valid JSON
External program failed to produce valid JSON
Error: Unsupported argument in child module call
How to fix "Unsupported argument in child module call" in Terraform
Error: network is unreachable
How to fix "network is unreachable" in Terraform