I can't remove an AWS Instance (AMI) volume using Terraform

525 views
Skip to first unread message

Asier Gomez

unread,
Mar 15, 2017, 7:18:52 AM3/15/17
to Terraform

I deploy a CentOS 7 using an AMI that automatically creates a volume on AWS, so when I remove the platform using the next Terraform commands:

terraform plan -destroy -var-file terraform.tfvars -out terraform.tfplan
terraform apply terraform.tfplan 
 

I just try to destroy using simple:

terraform destroy


The volume doesn't remove because it was created automatically with the AMI and terraform doesn't create it. Is it possible to remove with terraform?

My AWS instance is created with the next terraform code:


resource "aws_instance" "DCOS-master1" {
    ami = "${var.aws_centos_ami}"
    availability_zone = "eu-west-1b"
    instance_type = "t2.medium"
    key_name = "${var.aws_key_name}"
    security_groups = ["${aws_security_group.bastion.id}"]
    associate_public_ip_address = true
    private_ip = "10.0.0.11"
    source_dest_check = false
    subnet_id = "${aws_subnet.eu-west-1b-public.id}"

    tags {
            Name = "master1"
        }
}

Really thanks!!

Andrew Langhorn

unread,
Mar 15, 2017, 12:59:09 PM3/15/17
to terrafo...@googlegroups.com
Not that I'm aware of, but maybe you could import the volume using its volume ID? https://www.terraform.io/docs/providers/aws/r/ebs_volume.html

That way, Terraform would know about it.
And then you could maybe delete it.

But you'd have to import it after every terraform apply.
Which probably means hooking in to the AWS API somehow after Terraform has run.

egul...@gmail.com

unread,
Mar 15, 2017, 6:36:51 PM3/15/17
to Terraform, andrew....@thoughtworks.com
Did you create that AMI?
If you did then my advice would be to spin up ec2 (manually) using that AMI, stop ec2, create NEW AMI & check the option to TERMINATE additional volumes and use that NEW AMI in your terraform code.

Asier Gomez

unread,
Mar 16, 2017, 4:29:50 AM3/16/17
to Terraform, andrew....@thoughtworks.com
Really thanks for your response, but I don't create the AMI is a default CentOS AMI of AWS. Maybe the volume is protected?

Asier Gomez

unread,
Mar 16, 2017, 4:31:26 AM3/16/17
to Terraform, andrew....@thoughtworks.com
Okey I would try it, but the problem is that I can't automatice this, I have to access to aws console to add the ID, so there I can remove it, but what I need is to remove all the infraestructure automatically :S. Any idea how can I do that automatically? Really thanks for your help

Asier Gomez

unread,
Mar 17, 2017, 5:10:38 AM3/17/17
to Terraform, andrew....@thoughtworks.com
It works for me really thanks!!!


El miércoles, 15 de marzo de 2017, 17:59:09 (UTC+1), Andrew Langhorn escribió:
Reply all
Reply to author
Forward
0 new messages