Skip to content
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

plan: also validate provider requirements from state #35864

Merged
merged 1 commit into from
Oct 16, 2024

Conversation

liamcervante
Copy link
Member

@liamcervante liamcervante commented Oct 16, 2024

This PR updates the validation of required providers so that it also makes sure any providers required by the state are included. This improves the error message returned when a resource is in state but not in config and has no included provider.

Before

╷
│ Error: failed to read schema for null_resource.resource in registry.terraform.io/hashicorp/null: failed to instantiate provider "registry.terraform.io/hashicorp/null" to obtain schema: unavailable provider "registry.terraform.io/hashicorp/null"
│ 
│ 
╵

After

╷
│ Error: Missing required provider
│ 
│ This state requires provider registry.terraform.io/hashicorp/null, but that provider isn't available. You may be able to install it automatically by
│ running:
│   terraform init
╵

Fixes #35860

Target Release

1.9.x

Draft CHANGELOG entry

ENHANCEMENTS

  • Improve error message when provider is required by state but has not been downloaded.

@liamcervante liamcervante requested a review from a team October 16, 2024 08:39
@liamcervante liamcervante added the 1.9-backport If you add this label to a PR before merging, backport-assistant will open a new PR once merged label Oct 16, 2024
tfdiags.Error,
"Missing required provider",
fmt.Sprintf(
"This state requires provider %s, but that provider isn't available. You may be able to install it automatically by running:\n terraform init",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may be able to install it automatically

What is that dependent on? The provider being in the required provider section?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Defined anywhere in the configuration or the state. This basically catches someone running plan or apply before they ran init. We do the same check with a similar error message in case something is in config and hasn't been caught: https://github.com/hashicorp/terraform/blob/main/internal/terraform/context.go#L389

init won't install automatically if the configuration is wrong, or it's not a default provider and isn't in the required providers. But all cases init will then provide specific error messages for why something couldn't be installed.

@liamcervante liamcervante merged commit aaeefbe into main Oct 16, 2024
6 checks passed
@liamcervante liamcervante deleted the liamcervante/35860 branch October 16, 2024 12:13
Copy link
Contributor

Reminder for the merging maintainer: if this is a user-visible change, please update the changelog on the appropriate release branch.

Copy link
Contributor

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
1.9-backport If you add this label to a PR before merging, backport-assistant will open a new PR once merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

failed to read provider configuration schema for registry.terraform.io/hashicorp/null
2 participants