command/init: Restore the unconstrained provider warnings #24559
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When a provider dependency is implicit rather than explicit, or otherwise when version constraints are lacking, we produce a warning recommending the addition of explicit version constraints in the configuration.
This restores the warning functionality from previous Terraform versions, adapting it slightly to account for the new provider FQN syntax and to recommend using a
required_providers
block rather than version constraints inprovider
blocks, because the latter is no longer recommended in the documentation.Due to the constraints of how we're presenting this information the warning message might imply to a user new to Terraform that it's recommending putting a
required_providers
block at the toplevel of configuration, and so to help guide towards the right answer I also added here a specialized error message in theconfigs
package for that case. I'm expecting that this won't be the only place (either in our own prose or in third-party prose) where a configuration snippet without sufficient context might give the false impression thatrequired_providers
is a top-level block type.This commit also removes two other TODO comments while appearing not to do anything about them. That's because both of those are now addressed in a slightly different way by the underlying provider installer object:
The selections are captured into a file automatically by the installer, though it's a different file with a different internal structure than was generated by the commented-out code that I removed here.
We're no longer actively "pruning" unused packages from the cache here, because the main reason we did that before was to work around the fact that our discovery package considered the files in the directory as the source of record for which versions were selected and so having other versions there would cause misbehavior.
The new selections file format includes exact version information, so we no longer need to prune. We might choose to re-instate automatic cache management later for general disk space management reasons, but the focus on this commit was on the mandatory behavior required to get the tests passing again.
As with my last few PRs, this one is targeting our integration branch represented as #24477. However, this is hopefully the last changeset before that will land, because this should green the final remaining test failure: an existing e2etest specifically testing the unconstrained provider warnings.