- Notifications
You must be signed in to change notification settings - Fork16
Terraform destroy without configuration files
License
jckuester/terradozer
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Terraform destroy using the state only - no *.tf files needed
Terradozer takes a Terraform state file as input and destroys all resources it finds in it - without needing any *.tffiles. This works currently only for resources of the Terraform AWS Provider. If you need support for any other provider,let me know, and I will try to help.
Happy (terra)dozing!
- Nothing will be deleted without your confirmation. Terradozer always lists all resources first and then waits foryour approval
- Using the
-force
flag (dangerous!), terradozer can run in an automated fashion without human interaction and approval,for example, as part of your CI pipeline - Planned, if you want me to implement this,please upvote:Allow terradozer pointing directly to a state file stored in S3, i.e.,
terradozer s3://path/to/terraform.tfstate
- Planned, if you want me to implement this,please upvote:A
-recursive
flag to delete resources of all states found under a given directory, i.e.,terradozer -recursive s3://bucket-with-states/
. This is especially helpful ifyou orchestrate Terraform modules withTerragrunt and store all statesunder the same directory or in the same S3 bucket. This way, a complete Terragrunt project could be cleaned up in anautomated fashion.
It's recommended to install a specific version of terradozer available on thereleases page.
Here is the recommended way to install terradozer v0.1.2:
# install it into ./bin/curl -sSfL https://raw.githubusercontent.com/jckuester/terradozer/master/install.sh| sh -s v0.1.2
To delete all resources in a Terraform state file:
terradozer [flags] <path/to/terraform.tfstate>
To see all options, runterradozer --help
. Provide credentials for the AWS account you want to destroy resources invia the usualenvironment variables, e.g.,AWS_PROFILE=<myaccount>
andAWS_DEFAULT_REGION=<myregion>
.
The region information is needed as it is not stored as part of the state. Having multiple providers with differentregions in one state file is not yet supported.
Terradozer first scans a given Terraform state file (read-only) to find all resources (excluding data sources),then downloads the necessary Terraform Provider Plugins to call the destroy function for each resource on the respectiveCRUD API via GRPC (e.g., calling the Terraform AWS Provider to destroy aaws_instance
resource).
This section is only relevant if you want to contribute to Terradozer and therefore run the tests. Terradozer hasacceptance tests, integration tests checking against changes of behaviour in the Terraform Provider API, and of courseunit tests.
Run unit tests
make test
Run acceptance and integration tests
AWS_PROFILE=<myaccount> AWS_DEFAULT_REGION=<myregion> make test-all
About
Terraform destroy without configuration files