hashicorp / terraform

Terraform enables you to safely and predictably create, change, and improve infrastructure. It is a source-available tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned.
https://www.terraform.io/
Other
42.69k stars 9.55k forks source link

Backend Backing Store Should Be Deleted when removing backend #19283

Open berney opened 6 years ago

berney commented 6 years ago

When you use the various backends, such as azurerm backend, it creates a blob in a container in a storage account. When you remove the backend and re-run terraform init it will offer to pull the remote state local. However it does not delete the remote container/blob, and I cannot find a command or option to make it do this. The remote container/blob needs to be removed manually using other tools like Azure CLI. I'd like either re-init to offer to remove it (or just remove it), or a command or argument or similar to have terraform clean up after itself.

Terraform did not work the way I expected, hence this feature request.

Terraform Version

Terraform v0.11.9

Affected Resource(s)

Please list the resources as a list, for example:

Terraform Configuration Files

terraform {
    backend "azurerm" {
        storage_account_name = "storage"
        container_name       = "container"
        key                  = "key"
        resource_group_name  = "rg"
    }
}

Expected Behavior

Terraform should delete the blob it created

Actual Behavior

blob "key" under container "container" under storage account "storage" still exists.

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. configure the azurerm backend
  2. terraform init
  3. remove the azurerm backend config
  4. terraform init

References

Re-reading the documentation it doesn't state it will delete the backend. https://www.terraform.io/docs/backends/config.html#unconfiguring-a-backend

Use-cases

User wants to remove a backend, terraform cleans up after itself rather than leaving behind containers and accounts, etc.

Attempted Solutions

Read the docs, --help, googled around, logged a bug against azurerm provider, https://github.com/terraform-providers/terraform-provider-azurerm/issues/979, told to open one in core as that's the code responsible for the current behaviour.

Proposal

I'd like either re-init to offer to remove it (or just remove it), or a command or argument or similar to have terraform clean up after itself.

References

https://github.com/terraform-providers/terraform-provider-azurerm/issues/979

tombuildsstuff commented 6 years ago

@berney thanks for migrating this over :)

jrob commented 5 years ago

Agreed. I am manually cleaning up s3 and dynamodb. We run the risk of having clutter around that no one knows if its safe to remove or not.