Description
Describe the bug
Terraform Validate is broken when running in a module that uses provider aliases, which in turn breaks pre_commit validation checks.
How can we reproduce it?
When running the pre-commit with a module that has multiple providers defined like so:
terraform {
required_version = ">= 0.15"
providers {
aws = {
version = ">= 3.0"
configuration_aliases = [aws.other]
}
}
}
With some resource defined that uses provider = aws.other
When terraform validate runs it throws an error:
Error: Provider configuration not present
To work with data.aws_kms_key.other its original provider configuration at provider["registry.terraform.io/hashicorp/aws"].primary 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. Re-add the provider configuration to destroy data.aws_kms_key.primary, after which you can
remove the provider configuration again.
Environment information
The only that that matters in terms of the environment is that you're on a recent enough version of terraform to support module-based provider aliases (0.15+) and that you're using that feature and terraform_validate. It's a bug in terraform technically.