Skip to content

Use provider aliases from provider requirements #37172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

kerwanp
Copy link

@kerwanp kerwanp commented May 26, 2025

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

Target Release

1.12.2

Rollback Plan

  • 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

  • This change is user-facing and I added a changelog entry.
  • This change is not user-facing.

@kerwanp kerwanp requested a review from a team as a code owner May 26, 2025 20:27
@kerwanp kerwanp marked this pull request as draft May 26, 2025 20:30
@crw
Copy link
Contributor

crw commented May 27, 2025

Thanks for this submission. I will raise it in triage.

Copy link

CLA assistant check

Thank you for your submission! We require that all contributors sign our Contributor License Agreement ("CLA") before we can accept the contribution. Read and sign the agreement

Learn more about why HashiCorp requires a CLA and what the CLA includes

Have you signed the CLA already but the status is still pending? Recheck it.

@jgrumboe
Copy link

Any updates on this?
@kerwanp I think you also need to sign the CLA.

@crw
Copy link
Contributor

crw commented Jun 17, 2025

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants