-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
Terraform state commands should prompt before running #15283
Comments
Yikes, @xocasdashdash! Sorry for this startling behavior. This "match everything by default" behavior is common to several commands but I completely agree that it's a bad default for this command, given how destructive it is. At the very least we should make this command fail if no arguments are given. Prompting for approval is also an interesting idea, but might be trickier since these commands tend to be used by people in scripts. Let's start with just making it be mandatory to provide at least one argument, and see if having to correctly type out a resource address serves as confirmation enough, since that way we can avoid making a breaking change to scripts. (Except scripts that are intentionally deleting everything, but that seems unlikely.) |
@apparentlymart that sounds reasonable. Maybe change the |
Due to how the state filter machinery works, passing no arguments is valid and matches _all_ resources. It is very unlikely that someone wants to remove everything from state, so this ends up being a very dangerous default for the "terraform state rm" command, and surprising for someone who perhaps runs it looking for the usage information. So we'll be pragmatic here and reject the no-arguments case for this command, accepting that it makes the unlikely case of intentionally deleting all resources harder in order to make it less likely that it will happen _unintentionally_. If someone does really want to remove all resources from the state, they can provide an explicit empty string argument, but this isn't documented because it's a weird case that doesn't seem worth mentioning. This fixes #15283.
Due to how the state filter machinery works, passing no arguments is valid and matches _all_ resources. It is very unlikely that someone wants to remove everything from state, so this ends up being a very dangerous default for the "terraform state rm" command, and surprising for someone who perhaps runs it looking for the usage information. So we'll be pragmatic here and reject the no-arguments case for this command, accepting that it makes the unlikely case of intentionally deleting all resources harder in order to make it less likely that it will happen _unintentionally_. If someone does really want to remove all resources from the state, they can provide an explicit empty string argument, but this isn't documented because it's a weird case that doesn't seem worth mentioning. This fixes #15283.
Thanks for pointing this out @xocasdashdash! I just merged the change we discussed and so it should be included in the forthcoming 0.10.0 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. |
I'm trying to fix a state issue (not related) and while exploring the terraform state command i accidentally deleted it after running:
terraform state rm
IMHO this command should not destroy the state when run without any arguments.
Terraform Version
Terraform v0.9.8
Expected Behavior
Nothing should have been deleted from the state.
Actual Behavior
Everything was deleted
Steps to Reproduce
terraform state rm
The text was updated successfully, but these errors were encountered: