-
Notifications
You must be signed in to change notification settings - Fork 9.7k
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
command: Fix init flags silent exit bug #25300
Conversation
When using `-flag=value` with Powershell, unquoted values are broken into separate arguments. This means that the following command: terraform init -backend-config=./backend.conf is interpreted by Terraform as: terraform init -backend-config= ./backend.conf This results in an empty backend-config setting (which is semantically valid!) followed by a custom configuration path (pointing at a file). Due to a bug where we could exit without printing diagnostics, this would result in a silent failure that was very difficult to diagnose.
Codecov Report
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! Looks like not showing the error messages here was a result of an incorrect adaptation of an old implementation prior to diagnostics.
With that said, you got me thinking about the -backend-config=
(zero-length value after =
) case a little: isn't it the case that this must either be a filename or a key=value
string? If so, I think that an empty string could never be either of those, and so we could potentially have a more tailored error message here noting that the option value is invalid.
This will still, of course, remain confusing under PowerShell: PowerShell's insistence on inserting unrequested spaces in the command line means that the result would still be pretty confusing, and appear as a Terraform bug rather than a PowerShell parsing quirk:
PS C:\> terraform init -backend-config=./foo
Error: Module directory ./foo does not exist
Error: -backend-config= requires an argument
Without being able to reliably detect that the calling program is PowerShell here I don't really see any robust way to do better: what the user entered and what PowerShell passes to us are different in an infuriatingly-subtle yet significant way. 😖
Sadly I don't think this is possible. While I can't find where this is documented (if it is), the command interprets an empty string value as meaning "remove all previous Lines 777 to 781 in 69b94ec
This was introduced in #21439. I'm also not satisfied with this current solution to the bug, but at least having some error message displayed would give the user a chance of figuring out that there's a quoting issue happening. I'm not targeting this at 0.13.0 anyway (since we're close to an RC), so maybe a better solution will occur to us before merge 🤞 |
Oh yes, I'd forgotten about that tricky overloading of |
After thinking about this some more I've changed my mind. Given the tiny scope of this change, I think it's low enough risk that it's better to merge now than leave this silent failure edge case to trip someone else up. |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
When using
-flag=value
with Powershell, unquoted values are broken into separate arguments. This means that the following command:is interpreted by Terraform as:
This results in an empty backend-config setting (which is semantically valid!) followed by a custom configuration path (pointing at a file).
Due to a bug where we could exit without printing diagnostics, this would result in a silent failure that was very difficult to diagnose. See #25266.