Skip to main content
Knowledge Base

Preserve data volume when destroying single-server module?

Answer

When using the single-server module. Why does the `delete_on_termination` parameter work for the root device but not work for an `ebs_block_device`? Trying to preserve a data volume in case of destroy.

The single-server module only manages the root block device, and doesn’t provision/manage additional EBS block devices. One way you can avoid the destroy of block devices is by managing the EBS volume in a separate state file. E.g., create a module that manages the lifecycle of the EBS volume (these two blocks: https://github.com/gruntwork-io/terraform-aws-server/blob/master/examples/persistent-ebs-volume/main.tf#L62-L83), and then use the [persistent-ebs-volume](https://github.com/gruntwork-io/terraform-aws-server/tree/master/modules/persistent-ebs-volume) script to manage mounting that volume on the EC2 instance. Since the EBS volume is mounted via the `user_data` script, it should ensure that the volume is preserved even if you destroy the EC2 instance, and will remain until you destroy the other module that is managing the actual volume. credit to @yorinasub17