【问题标题】:Need to refactor an inline resource into a separate resource in terraform?需要将内联资源重构为 terraform 中的单独资源吗?
【发布时间】:2018-07-24 01:21:32
【问题描述】:

一般来说,我如何重构内联资源并使用单独的卷资源将其作为单独的资源移到外部。

例如,有没有办法重构 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
  }

}

【问题讨论】:

    标签: terraform terraform-provider-openstack


    【解决方案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}"
    }
    

    【讨论】:

    • 我需要的是通过重构将block_device变为openstack_compute_instance_v2资源,而不必删除卷并重新创建。
    猜你喜欢
    • 1970-01-01
    • 2020-01-21
    • 2019-11-30
    • 2019-06-18
    • 2023-01-08
    • 1970-01-01
    • 2021-02-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多