Skip to main content
3 of 4
include more data on the associated volume.
cueedee
  • 151
  • 6

How to `terraform destroy` an `aws_instance` without also destroying its `aws_ebs_volume` (separate resource)

$ terraform -version
Terraform v0.12.21
+ provider.aws v2.34.0

Given a terraform configuration for one set of single aws_instance, aws_ebs_volume and aws_volume_attachment resources, each named, say,foo;

How would one terraform destroy -target=aws_instance.foo without terraform also destroying the aws_ebs_volumen.foo as the resulting plan insists that it will?

  • The aws console reports Delete on termination for the volume's block device to be false;
  • I've tried to terraform destroy -target=aws_volume_attachement.foo first;
    ... no-change.
  • I've tried removing the aws_volume_attachment from the configuration, terraform apply it and then terraform destroy -target=aws_instance.foo;
    ... didn't help either

Somehow terraform really wants to destroy the aws_ebs_volume resource together with the aws_instance resource.

I, otoh, would very much like to preserve that aws_ebs_volume for later attachment to a re-created aws_instance...

Can it be done?

cueedee
  • 151
  • 6