Terraform-provider-aws: Please add a flag to aws_ebs_volume resource to prevent deletion on termination

Created on 23 Nov 2017  路  6Comments  路  Source: hashicorp/terraform-provider-aws

Hi there,

Terraform Version

Terraform v0.10.6
provider.aws: version = "~> 1.3"

Affected Resource(s)

  • aws_ebs_volume

Terraform Configuration Files

resource "aws_ebs_volume" "ebs_master-eu-west-1a" {
  availability_zone = "eu-west-1a"
  size              = 100
  type              = "gp2"
  encrypted         = false
  tags {
    Name = "ebs_master-eu-west-1a"
  }
}

resource "aws_volume_attachment" "ebs_master-eu-west-1a" {
  device_name  = "/dev/sdc"
  skip_destroy = true
  volume_id    = "${aws_ebs_volume.ebs_master-eu-west-1a.id}"
  instance_id  = "${aws_instance.master-eu-west-1a.id}"
}

Expected Behavior

If you use the 'block_device' mapping within the aws_instance resource definition you can prevent it from being destroyed upon termination:

https://www.terraform.io/docs/providers/aws/r/instance.html#delete_on_termination-1

But this does option not appear in the ebs_volume resource:

https://www.terraform.io/docs/providers/aws/r/ebs_volume.html

Please can this flag also be added to the aws_ebs_volume resource?

Actual Behavior

Volume is destroyed/deleted

Steps to Reproduce

  1. terraform destroy
enhancement servicec2

Most helpful comment

+1

All 6 comments

Hi @TristanPeers!

An EBS volume created via aws_ebs_volume should have a lifecycle entirely separate from any EC2 instance it is attached to, so I think "delete on termination" isn't really a meaningful option here... it must always be false by definition.

However, perhaps I misunderstand what you're seeing and what you'd like to achieve here. If you can give a little more detail on your goals here it might help us to understand what is needed to meet those goals.

Thanks!

Hi @apparentlymart - many thanks for your response and for not dismissing the idea immediately, I really appreciate that!
I totally understand about the separate lifecycle and was expecting the issue to be closed saying 'not possible' or something along those lines, however I thought I would ask the question anyway.

We destroy and build several thousand servers each day in AWS (using our own in-house provisioning code) and are attempting to migrate away from our own code to use Terraform to do this instead. All the instances have their software installed at boot time by configuration management software (Puppet) and their data is persisted/stored on EBS volumes which are re-attached at boot. This means we can destroy all of the non-production instances overnight to save running costs.

I know we can specify exact resources to be destroyed (and thus exclude ebs volumes): terraform destroy -target=XXX but the instances have many, many resources defined so this starts to get messy and also some instances have different resources defined so we can't use the same set of destroy commands globally.

It would be much easier if aws_ebs_volume had the 'delete_on_termination' flag like block device mapping does to prevent it being destroyed. The ebs volumes (data) are the only resource we need to keep/persist, everything else is provisioned each day.

I fully understand about volumes being a different realm to instances so this is probably an AWS limitation, not a Terraform limitation?

Hope this explains the reasoning behind the request and even if it's not possible right now, maybe it could be considered for the future.

Thanks again.

Any updates on this?

+1

@apparentlymart could you look into this? Really needed functionality

Totally agree with @TristanPeers.
Extremely necessary.

Was this page helpful?
0 / 5 - 0 ratings