Hello, we have an unfortunate situation where a user deleted an AWS resource which should have been locked, and now we want to restore it, however because this resource is missing, other resources that are dependant on it cant be Destroyed/Planned/Applyed.
What is the go-to way of solving this issue?
My next try is gonna be deleting all the remaining resources manually as well and then deploying everything from scratch, but that could turn into a huge task, which i would rather solve with Terraform if possible.
Hi @Somethingsomeasd
Welcome to the community. A very quick answer as I imagine you need it soon!
Create the missing resource without using Terraform and then import it in your local Terraform using the same it had before:
Importing a new object is a good answer indeed, @javierruizjimenez!
Another possible option is to tell Terraform to “forget” about the now-deleted object, using terraform state rm
. That command removes the binding from the Terraform resource instance to the now-deleted remote object, and so on the next terraform apply
Terraform will consider that object as needing to be created.
(Be careful with terraform state rm
when working with objects that haven’t been deleted outside of Terraform: once Terraform “forgets” an object it will not make any further changes to it, including deleting it, and so inappropriate use of this command can cause you to have objects in the remote system that are not tracked anywhere, which may cost money and/or cause confusion.)
2 Likes
Super useful during development , thanks @apparentlymart