terraform
terraform copied to clipboard
Use provider aliases from provider requirements
Problem
The following module requires 2 providers test and test.secondary.
terraform {
required_providers {
test = {
source = "hashicorp/test"
configuration_aliases = [ test.secondary ]
}
}
}
resource "test_resource" "primary" {
value = "foo"
}
resource "test_resource" "secondary" {
provider = test.secondary
value = "bar"
}
When running the command terraform validate we are prompted with the following error:
Error: Provider configuration not present
To work with aws_route53_zone.this its original provider configuration at provider["registry.terraform.io/hashicorp/aws"].subzone 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 aws_route53_zone.this, after which you can remove the provider configuration again.
This is due to the fact that terraform.required_providers[*].configuration_aliases are not added to the required providers in the graph.
Solution
By iterating over the required provider aliases and add them to the graph they can be properly resolved and terraform validate works properly on standalone modules.
Fixes
- #28490
Target Release
1.12.2
Rollback Plan
- [x] If a change needs to be reverted, we will roll out an update to the code within 7 days.
Changes to Security Controls
There are no changes to security controls
CHANGELOG entry
- [x] This change is user-facing and I added a changelog entry.
- [ ] This change is not user-facing.
Thanks for this submission. I will raise it in triage.
Any updates on this? @kerwanp I think you also need to sign the CLA.
Apologies - we reviewed this in triage. It would require a deeper review to validate, and unfortunately was not deemed a priority at the time. The original issue is getting close to cracking the top 25 issues by upvotes, so it may be able to be revisited in a subsequent release. Thanks!
I've already signed the CLA but it does not seem to get updated. Happy to see that this issue is moving forward!
I'm not sure what the overall intent of the change was supposed to be, but this immediately breaks implied provider configuration coming from root modules since it is now relying on configuration_aliases which are not used in normal root modules (as shown in the unit test failures).
While there might still be some way to reevaluate the intended behavior of validate with regards to aliased providers, it would be better if any changes were designed more specifically with the validate codepath in mind. Until we can make breaking changes with a major release, there are a lot of subtle implied behaviors of providers which need to be preserved.
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions. If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.