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

Terraform state commands should prompt before running #15283

Closed
xocasdashdash opened this issue Jun 14, 2017 · 4 comments · Fixed by #15479
Closed

Terraform state commands should prompt before running #15283

xocasdashdash opened this issue Jun 14, 2017 · 4 comments · Fixed by #15479

Comments

@xocasdashdash
Copy link
Contributor

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

  1. terraform state rm
@apparentlymart
Copy link
Contributor

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

@xocasdashdash
Copy link
Contributor Author

@apparentlymart that sounds reasonable. Maybe change the terraform state output to reflect that too.

apparentlymart added a commit that referenced this issue Jul 5, 2017
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.
apparentlymart added a commit that referenced this issue Jul 5, 2017
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.
@apparentlymart
Copy link
Contributor

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.

@ghost
Copy link

ghost commented Apr 8, 2020

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.

@ghost ghost locked and limited conversation to collaborators Apr 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants