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

Bug fix: Terraform workspace command returns zero exit code when given an invalid argument. #31318

Conversation

twittyc
Copy link
Contributor

@twittyc twittyc commented Jun 24, 2022

The Terraform workspace command will return a 0 return code even when invalid arguments are passed to the command.
For example, terraform workspace seleect will return a 0 (non-error) return code even though it's an invalid command. This PR updates the Run method to fall in line with other terraform commands and returns a proper non-zero return code when an invalid argument is passed to terraform workspace.

➜  linux_amd64 git:(twittyc/terraformWorkspaceInvalidArgsReturnsNon0) terraform workspace seleect
Usage: terraform [global options] workspace

  new, list, show, select and delete Terraform workspaces.
➜  linux_amd64 git:(twittyc/terraformWorkspaceInvalidArgsReturnsNon0) echo $?
0

This fix updates the return code to properly give an error

➜  linux_amd64 git:(twittyc/terraformWorkspaceInvalidArgsReturnsNon0) terraform workspace seleect
Usage: terraform [global options] workspace

  new, list, show, select and delete Terraform workspaces.
➜  linux_amd64 git:(twittyc/terraformWorkspaceInvalidArgsReturnsNon0) echo $?
1

go tests pass. Let me know if I need to do anything else or if you have any feedback :)

@hashicorp-cla
Copy link

hashicorp-cla commented Jun 24, 2022

CLA assistant check
All committers have signed the CLA.

@twittyc
Copy link
Contributor Author

twittyc commented Jun 24, 2022

This closes #31317

@crw
Copy link
Collaborator

crw commented Jun 27, 2022

Thanks for this submission! Although I cannot commit to having this PR reviewed at this time, we acknowledge your contribution and appreciate it!

@crw crw added the bug label Jun 27, 2022
@jbardin jbardin self-assigned this Oct 14, 2022
@jbardin jbardin merged commit d60d247 into hashicorp:main Dec 16, 2022
@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 Jan 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unknown workspace sub-command should bail with non-zero exit code
4 participants