-
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: adjust exit code of state rm #22300
command: adjust exit code of state rm #22300
Conversation
Commands `state rm` and `state mv` will now exit with code 1 when the target resource is not found in the current state. This is consistent with `terraform state show non_existent_resource`. Fixes hashicorp#17800
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.
Hi @jgpacker, thanks for this contribution! I tried out your patch and it works as described, however, now that exit code is 1, we should show an error to the user versus showing UI output -- so that the experience is consistent (the command errored, so an error is displayed).
In Terraform, our best practice to add an error is using the tfdiags
package, where a summary, and then more helpful information is shared so the user can amend their error. In this scenario, something like (this uses some language from the error displayed when you use terraform show
on the non-existent resource) could replace the current UI output in state rm
:
diags = diags.Append(tfdiags.Sourceless(
tfdiags.Error,
"Invalid target address",
"No matching objects found. To view the available instances, use "terraform state list". Please modify the address to reference a specific instance.",
))
c.showDiagnostics(diags)
return 1
Thank you for the feedback. I will correct this soon |
I have updated the code according to the feedback. Unfortunately I have not been able to test it locally right now. So there might be still be some adjustments to be done. Thank you in advance for the review |
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.
One improvement for state_mv, since we have a constant that already exists.
I had trouble figuring out a flow of terraform state mv
that would hit this while testing on my machine -- perhaps you could add a test to state_mv_test.go hitting this error?
@pselle I opened this PR only to fix |
Ah in that case (if you haven't been able to replicate through with |
Thank you for the orientation. I have reverted the changes in |
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.
Thanks for the nudge @jgpacker. I'm approving this, but tagging it with "breaking-change" as the related issue has the same tag, so this will need to go out in the 0.13 release vs a 0.12.x release.
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. |
Command
state rm
will now exit with code 1 when the resource is not found in the current state.This is consistent with
terraform state show non_existent_resource
.Fixes #17800