Skip to content

Check required_version as early as possible#29665

Merged
jbardin merged 4 commits intomainfrom
jbardin/required_version
Sep 29, 2021
Merged

Check required_version as early as possible#29665
jbardin merged 4 commits intomainfrom
jbardin/required_version

Conversation

@jbardin
Copy link
Copy Markdown
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 force-pushed the jbardin/required_version branch from 37a3297 to 5532f4c Compare September 28, 2021 17:30
@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
We don't need to load the configuration twice, since configload can
return the module for us.
@jbardin jbardin force-pushed the jbardin/required_version branch from 5532f4c to ab0322e Compare September 28, 2021 21:58
Copy link
Copy Markdown

@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

@jbardin jbardin merged commit f93f168 into main Sep 29, 2021
@jbardin jbardin deleted the jbardin/required_version branch September 29, 2021 12:18
@github-actions
Copy link
Copy Markdown
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 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