Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

terraform lifecycle prevent destroy

I am working with Terraform V11 and AWS provider; I am looking for a way to prevent destroying few resources during the destroy phase. So I used the following approach.

lifecycle {
    prevent_destroy = true

} 

When I run a "terraform plan" I get the following error.

the plan would destroy this resource, but it currently has 
lifecycle.preven_destroy set to true. to avoid this error and continue with the plan. 
    either disable or adjust the scope. 

All that I am looking for is a way to avoid destroying one of the resources and its dependencies during the destroy command.

like image 865
Moe Avatar asked Apr 27 '20 04:04

Moe


Video Answer


1 Answers

The easiest way to do this would be to comment out all of the the resources that you want to destroy and then do a terraform apply.

like image 115
Cargo23 Avatar answered Oct 02 '22 10:10

Cargo23