TerraformPilot

Troubleshooting

Fix Terraform Error - Provider Configuration Not Present

Fix the Terraform provider configuration not present error. Covers missing providers in modules, provider aliasing, required_providers blocks, and state moves.

LLuca Berton2 min read

Quick Answer

#

A resource in state references a provider that isn't configured in your current Terraform files. Add the missing provider block, pass providers to modules explicitly, or remove the orphaned resource from state.

The Error

#
Error: Provider configuration not present
 
To work with aws_instance.web its original provider configuration
at provider["registry.terraform.io/hashicorp/aws"] is required,
but it has been removed. This occurs when a provider configuration
is removed while objects created by that provider still exist in
the state.
Error: Provider configuration not present
 
To work with module.network.aws_vpc.main its original provider
configuration at module.network.provider["registry.terraform.io/hashicorp/aws"].west
is required, but it has been removed.

What Causes This Error

#

1. Provider Block Removed

#

You deleted the provider "aws" {} block but resources using it still exist in state.

2. Provider Alias Removed

#

You had provider "aws" { alias = "west" } and removed it while resources using provider = aws.west are still in state.

3. Module Provider Not Passed

#

A child module needs a provider that wasn't explicitly passed via the providers argument.

4. State Contains Orphaned Resources

#

Resources were moved or refactored, and the state still references the old provider configuration.

How to Fix It

#

Solution 1: Add the Missing Provider Block

#
# If you removed the provider, add it back
provider "aws" {
  region = "us-east-1"
}
 
# If it was an aliased provider
provider "aws" {
  alias  = "west"
  region = "us-west-2"
}

Solution 2: Pass Providers to Modules

#
provider "aws" {
  region = "us-east-1"
}
 
provider "aws" {
  alias  = "west"
  region = "us-west-2"
}
 
module "network" {
  source = "./modules/network"
 
  # Explicitly pass providers to the module
  providers = {
    aws      = aws          # Default provider
    aws.west = aws.west     # Aliased provider
  }
}

In the module:

# modules/network/providers.tf
terraform {
  required_providers {
    aws = {
      source                = "hashicorp/aws"
      configuration_aliases = [aws.west]
    }
  }
}

Solution 3: Remove Orphaned Resources from State

#
# List all resources in state
terraform state list
 
# Remove the orphaned resource (doesn't delete the real resource)
terraform state rm aws_instance.old_server
 
# Or remove a module's resources
terraform state rm module.old_network

Solution 4: Replace Provider in State

#

If the provider changed (e.g., moved from hashicorp/aws to a custom registry):

# Replace the provider in state
terraform state replace-provider \
  "registry.terraform.io/hashicorp/aws" \
  "registry.terraform.io/hashicorp/aws"

Solution 5: Move Resources Between Providers

#
# Use moved blocks (Terraform 1.1+)
moved {
  from = aws_instance.old
  to   = module.compute.aws_instance.main
}
# Or use state mv
terraform state mv aws_instance.old module.compute.aws_instance.main

Common Scenarios

#
ScenarioCauseFix
Removed provider blockResources still in stateAdd provider back or state rm
Removed provider aliasResources use provider = aws.westAdd alias back or state rm
Module doesn't receive providerMissing providers argumentAdd providers = { aws = aws }
Changed provider sourceRegistry URL changedstate replace-provider
Refactored modulesResources movedstate mv or moved blocks

Troubleshooting Checklist

#
  1. ✅ Which provider is missing? (Check the error message)
  2. ✅ Was a provider block or alias removed recently?
  3. ✅ Does a child module need explicit providers passthrough?
  4. ✅ Are there orphaned resources in state? (terraform state list)
  5. ✅ Do you need the resource, or can you state rm it?

Prevention Tips

#
  • Don't remove providers until all their resources are destroyed
  • Always pass providers explicitly to modules that use aliased providers
  • Use terraform state list before removing provider blocks
  • Use moved blocks when refactoring — keeps state consistent
  • Use required_providers in all modules — makes dependencies explicit
#

Conclusion

#

Provider not present errors mean state references a provider that no longer exists in your config. Add the provider block back, pass it to modules with the providers argument, or remove orphaned resources from state with terraform state rm. Always check terraform state list before removing providers.

#provider#configuration#module

Share this article