为什么Terraform正在更新卷附件资源?

我正在使用Terraform来configurationCinder块设备附件的虚拟机群集。 问题是,当我播放Terraform或者只是扩展VM的数量时,Terraform计划更新现有VM的块设备附件(意思是删除附件资源,然后创build)。

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)}" } 

地形计划的输出。 第一个附件([2])是存在的,第二个([3])是为一个新的VM /块

 -/+ 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)}" 

如何才能使Terraform不改变现有的附件?

看来你的资源依赖于variables,这就是为什么地形看作是一种新的资源。 但是你总是可以忽略其中的任何一个来防止重新创build:

 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"] } }