是否需要将内联资源重构为terraform中的单独资源?

时间:2018-07-23 14:52:48

标签: terraform terraform-provider-openstack

通常,我如何重构内联资源,并使用单独的卷资源将其作为单独的资源移出外部。

例如,是否有一种方法可以重构block_device并将其移到openstack_compute_instance_v2之外,如下所示?

resource "openstack_compute_instance_v2" "instance_sakani_front_end_x" {
  ...
  block_device {
    uuid                  = ""
    volume_size           = 30
    boot_index            = 0
    destination_type      = "volume"
    delete_on_termination = true
  }

}

1 个答案:

答案 0 :(得分:1)

您可以将block_device拉出本地地图变量

   resource "openstack_compute_instance_v2" "instance_sakani_front_end_x" {
      ...
      block_device {
        uuid                  = ""
        volume_size           = 30
        boot_index            = 0
        destination_type      = "volume"
        delete_on_termination = true
      }
    }

就像

locals {
    my_block_device {
        volume_size           = 30
        boot_index            = 0
        destination_type      = "volume"
        delete_on_termination = true
    }
}   

resource "openstack_compute_instance_v2" "instance_sakani_front_end_x" {
  ...
  block_device = "${local.my_block_device}"
}