1

Terraform destroys and creates new AWS resources when I modify the modules with new resources.

I tried with:

lifecycle {
  prevent_destroy = true
}

Getting the below error :

the plan would destroy this resource, but it currently has
lifecycle.prevent_destroy set to true. To avoid this error and continue with the
plan, either disable lifecycle.prevent_destroy or adjust the scope of the 
plan using the -target flag.

Is there any method to update terraform without launching new resources?

Note: when 'terraform plan' is run, shows "(forces new resource)" for Instance id and ebs_block device

10
  • 6
    This can depend a lot on the resource. Can you show which AWS resource you're trying to use, and what the plan looks like? Aug 5 '19 at 13:27
  • 2
    perhaps you need to import it into the state, so that terraform can manage it Aug 5 '19 at 15:15
  • @Kiran Terraform will destroy deployed resources depending on what you change in your code. Simply changing a tag, for example, does not warrant destroy/deploy actions. Can you offer code snippets of before and after that is triggering the destroy? Aug 8 '19 at 23:51
  • Welcome to Terraform. It does that. Unfortunately you only find out after you've bet the farm on it...
    – Gaius
    Aug 26 '19 at 8:14
  • @BruceBecker The terraform apply "forces new resources" on the following AWS services : instance id, ebs_block_device.delete_on_termination, ebs_block_device.device_name, ebs_block_device.encrypted, ebs_block_device.snapshot_id, ebs_block_device.volume_size, ebs_block_device.volume_type
    – Kiran
    Sep 3 '19 at 15:24