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

Check required_version as early as possible #29665

Merged
merged 4 commits into from
Sep 29, 2021
Merged

Conversation

jbardin
Copy link
Member

@jbardin jbardin commented Sep 28, 2021

Our current check of required_version happens after parsing the configuration, which may not be possible if new configuration constructs have been added to the language since the declared required_version. This can cause terraform to print rather unhelpful error messages about unknown identifiers in various modules, when the only pertinent information is that the CLI version is not compatible.

Restructure the init command to ensure that we check the core version constraints before handling any parsing diagnostics. We can remove the extra loading of the configuration, which is redundant when the config loader can return the same value along with its diagnostics.

Closes #29109

@jbardin jbardin requested a review from a team September 28, 2021 17:19
@jbardin jbardin self-assigned this Sep 28, 2021
We must ensure that the terraform required_version is checked as early
as possible, so that new configuration constructs don't cause init to
fail without indicating the version is incompatible.

The loadConfig call before the earlyconfig parsing seems to be unneeded,
and we can delay that to de-tangle it from installing the modules which
may have their own constraints.

TODO: it seems that loadConfig should be able to handle returning the
version constraints in the same manner as loadSingleModule.
LoadConfig should return any parsed configuration in order for the
caller to verify `required_version`.
@jbardin jbardin added the 1.0-backport If you add this label to a PR before merging, backport-assistant will open a new PR once merged label Sep 28, 2021
internal/command/init.go Show resolved Hide resolved
We don't need to load the configuration twice, since configload can
return the module for us.
Copy link

@qijinhaocode qijinhaocode left a comment

Choose a reason for hiding this comment

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

test

@github-actions
Copy link

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 Oct 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
1.0-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.

configuration_aliases throws misleading error in 0.14.x even though required_version = ">= 0.15"
3 participants