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

command: terraform state rm to require at least one argument #15479

Merged
merged 1 commit into from
Jul 5, 2017

Conversation

apparentlymart
Copy link
Contributor

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.
@apparentlymart apparentlymart merged commit fee1197 into master Jul 5, 2017
@apparentlymart apparentlymart deleted the f-state-rm-confirm branch February 5, 2018 19:18
@jwdinkel
Copy link

Thank you for describing the empty string argument.

I think the example of deleting everything should be included in the documentation.
Delete all:
terraform state rm ""
After which
terraform init
will cause the system to be ready to execute a new deployment without modifying previous deployments. Perhaps useful if copying a folder that was previously used for another purpose. I think this is equivalent to deleting the tfstate except that it has the benefit of generating a tfstate backup file every time the rm command is executed, which might be useful.

@i255d
Copy link

i255d commented Jul 22, 2019

How do we delete everything?

@ghost
Copy link

ghost commented Jul 24, 2019

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 Jul 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Terraform state commands should prompt before running
4 participants