1

I am using Terraform to provision a cluster of VM with Cinder block device attachment. The problem is when I replay the Terraform or just scale the number of VM, Terraform plans to update the block device attachment for existing VMs (meaning a deletion of the attachment resource then a creation).

resource "openstack_compute_volume_attach_v2" "worker-hd1" {
  count     = "${var.worker_count}"
  volume_id = "${element(openstack_blockstorage_volume_v2.hdd1_volume.*.id,count.index)}"
  instance_id = "${element(openstack_compute_instance_v2.worker_node.*.id,count.index)}"
}

Output of terraform plan. The first attachment ([2]) is existing, the second ([3]) is for a new VM/block

-/+ openstack_compute_volume_attach_v2.worker-hd2[2] (new resource required)
      id:                                            "2310c2aa-bfbf-4135-a73a-972748578613/f8a1964a-6589-41e9-9bc4-a44bcc865c97" => <computed>
      device:                                        "/dev/vde" => <computed>
      instance_id:                                   "2310c2aa-bfbf-4135-a73a-972748578613" => "${element(openstack_compute_instance_v2.worker_node.*.id,count.index)}"
      region:                                        "fr1" => <computed>
      volume_id:                                     "f8a1964a-6589-41e9-9bc4-a44bcc865c97" => "${element(openstack_blockstorage_volume_v2.hdd2_volume.*.id,count.index)}"

  + openstack_compute_volume_attach_v2.worker-hd2[3]
      id:                                            <computed>
      device:                                        <computed>
      instance_id:                                   "${element(openstack_compute_instance_v2.worker_node.*.id,count.index)}"
      region:                                        <computed>
      volume_id:                                     "${element(openstack_blockstorage_volume_v2.hdd2_volume.*.id,count.index)}"

How is it possible to make Terraform not change existing attachment ?

1 Answer 1

2

It seems your resources depend on variables, that's why terraform see it as a new resources. But you can always ignore any of them to prevent re-creation:

resource "openstack_compute_volume_attach_v2" "worker-hd1" {
  count     = "${var.worker_count}"
  volume_id = "${element(openstack_blockstorage_volume_v2.hdd1_volume.*.id,count.index)}"
  instance_id = "${element(openstack_compute_instance_v2.worker_node.*.id,count.index)}"
  lifecycle {
    ignore_changes = ["volume_id","instance_id"]
  }
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .