I have terraform state file only, don’t have conf file which were used to create resources . How can I delete resources ? Is it possible to destroy resources without having conf files ?
To resolve this, I performed below steps -
- Copy .terraform folder from other projects which is having TF conf to my project directory
- Keep the state file in my project directory
- Created backed.tf to mention the local path of the state file.
- Then #terraform init
- Then run #terraform destroy,
Thanks for sharing what worked for you, @vasimjams!
I just want to confirm that a minimal configuration just to destroy objects recorded in a state snapshot must contain:
- A suitable backend configuration referring to the state.
- Provider configurations for any providers that the resources in the state refer to. (For some providers, they can infer the necessary information automatically from the environment if you have suitable credentials/etc configured there, but that’s not true for all providers.)
Depending on how the original configuration was designed, you might also need:
- Configuration for destroy-time provisioners and their associated
connection
blocks, if the system was relying on Terraform to take some special action at destroy time. -
module
blocks for any modules that themselves contained provider configurations, so that Terraform can then find the provider configurations in those modules. (We don’t recommend using provider configurations in nested modules because of this problem, but Terraform continues to support it for single-instance modules for backward compatibility only.) - Provider version constraints, if the state includes resources of types that are no longer supported by the latest version of the provider that created them, and thus the automatically-selected provider version would not know how to destroy the object.
I’ve tried this but it hasn’t worked for me. Can I destroy all resources with only a state file?
Two people have already confirmed above how this can be done.
Unless you want to provide specifics about exactly what did not work for you, I’m not sure there’s anything more to say.
To make it simple for future reference. Just create a terraform configuration with a local backend pointing to that state file. E.g.
In main.tf
:
terraform {
backend "local" {
path="your_statefile_here.json"
}
}
You can hopefully then terraform init
and terraform destroy
as usual.
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.