Skip to content

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

Merged
jbardin merged 2 commits intohashicorp:mainfrom
twittyc:twittyc/terraformWorkspaceInvalidArgsReturnsNon0
Dec 16, 2022
Merged

Bug fix: Terraform workspace command returns zero exit code when given an invalid argument.#31318
jbardin merged 2 commits intohashicorp:mainfrom
twittyc:twittyc/terraformWorkspaceInvalidArgsReturnsNon0

Conversation

@twittyc
Copy link
Copy Markdown
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
Copy Markdown

hashicorp-cla commented Jun 24, 2022

CLA assistant check
All committers have signed the CLA.

@twittyc
Copy link
Copy Markdown
Contributor Author

twittyc commented Jun 24, 2022

This closes #31317

@crw crw linked an issue Jun 27, 2022 that may be closed by this pull request
@crw
Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor

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
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 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