Re: [terraform] Trying to add volume to aws_instance results in instance being recreated

579 views
Skip to first unread message

Clint Shryock

unread,
Oct 19, 2015, 9:59:56 AM10/19/15
to terrafo...@googlegroups.com
Hello –

I believe you are hitting this issue here:


Essentially, because you have an ebs_block_device block in your configuration, the aws_instance wants to manage all of those devices. Adding an external one via the `aws_volume_attachment` introduces a new EBS Block that the aws_instance doesn't know about, and so sees a conflict in the count of ebs_block_devices it's expecting. The continuous plan is the result of Terraform wanting to converge your infrastructure with it's view of the world, e.g. that specific instance should have just 1 ebs_block_device. 

As a possible workaround, could you try using the new ignore_changes configuration option with the instance's ebs_block_devices? 


That should allow you to indicate to Terraform to ignore changes to the ebs_block_devices inside the instance. That may not be *perfect*, but it should allow you to continue without having to destroy the instance.

Let us know if that works!

--
Clint

On Sun, Oct 18, 2015 at 1:47 PM, Bao Nguyen <bng...@ctacorp.com> wrote:
Hey guys, 
I have an EC2 instance that was created with the following:

resource "aws_instance" "splunk-master" {
    ami = "${var.amis-east-ubuntu}"
    instance_type = "m3.medium"
    subnet_id = "${aws_subnet.subnet-east-svcs-1.id}"
    associate_public_ip_address = false
    private_ip = "${var.static-ips-east-svcs.splunk1}"
    iam_instance_profile = "ip-svcs"
    source_dest_check = true
    disable_api_termination = true
    user_data = "${file("templates/splunk1-cloud-init-east.yaml")}"
    key_name = "splunk-v1"
     lifecycle {
        prevent_destroy = false
    }
    tags {
        Name = "splunk-01.domain.local"
    }
    ebs_block_device {
        device_name = "/dev/sdf"
        volume_type = "gp2"
        volume_size = "100"
    }
    ebs_block_device {
        device_name = "/dev/sdg"
        volume_type = "gp2"
        volume_size = "50"
    }
}



We needed to expand the volume to allow for more logs so I added 200G using the following:


resource "aws_volume_attachment" "splunk_dev_sdh" {
  device_name = "/dev/sdh"
}

resource "aws_ebs_volume" "splunk_opt_extend" {
  availability_zone = "us-east-1a"
  size = 200
}





And did a terraform apply --target aws_volume_attachment. splunk_dev_sdh. The volume was added and aligned to the server, but I fear that I've broken the remainder of the terraform code...

When I run a terraform plan without any target, the output states that aws_instance.splunk-master-east-svcs-1 and aws_volume_attachment.splunk_dev_sdh will be recreated. Can you give me some guidance on what I did wrong, or what I'm missing?

Thanks!

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-too...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/f4b272fa-c675-4244-91a6-4afce4daba6a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Clint
Reply all
Reply to author
Forward
0 new messages