0
votes

In general, how can I refactor an inline resource and move it outside as a separate resource using a separate volume resource.

For example, is there a way to refactor a block_device and move it outside a openstack_compute_instance_v2 as shown below?

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

1 Answers

1
votes

You can pull the block_device out into a local map variable

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

Like so

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