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

cli: Improved error for invalid -var "foo = bar" #30985

Merged
merged 1 commit into from May 30, 2022

Conversation

alisdair
Copy link
Member

@alisdair alisdair commented May 3, 2022

When specifying variable values on the command line, name-value pairs must be joined with an equals sign, without surrounding spaces. Previously Terraform would interpret -var "foo = bar" as assigning the value " bar" to the variable named foo . This is never valid, as variable names may not include whitespace.

This commit looks for this specific error and returns a diagnostic with a suggestion for correcting it. We cannot simply trim whitespace, because it is valid to write -var "foo= bar" to assign the value " bar" to the variable foo, as unlikely as it seems.

Fixes #30600, see also documentation in #30969.

Screenshots

Before:

before

After:

after

When specifying variable values on the command line, name-value pairs
must be joined with an equals sign, without surrounding spaces.
Previously Terraform would interpret "foo = bar" as assigning the value
" bar" to the variable named "foo ". This is never valid, as variable
names may not include whitespace.

This commit looks for this specific error and returns a diagnostic with
a suggestion for correcting it. We cannot simply trim whitespace,
because it is valid to write "foo= bar" to assign the value " bar" to
the variable "foo", as unlikely as it seems.
@alisdair alisdair added the cli label May 3, 2022
@alisdair alisdair requested a review from a team May 3, 2022 13:20
@alisdair alisdair self-assigned this May 3, 2022
@alisdair alisdair added the 1.2-backport If you add this label to a PR before merging, backport-assistant will open a new PR once merged label May 30, 2022
@alisdair alisdair merged commit 06f6a90 into main May 30, 2022
@alisdair alisdair deleted the alisdair/var-flag-spaces-error branch May 30, 2022 14:40
@github-actions
Copy link

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

@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 Jun 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
1.2-backport If you add this label to a PR before merging, backport-assistant will open a new PR once merged cli
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Plan unable to execute with Space in key=value --> key = value
2 participants