【发布时间】:2022-07-06 07:13:22
【问题描述】:
我正在通过 terraform 创建一个 google_compute_instance 资源。
我需要附加一个启动盘和一个附加磁盘。所以在当地人我这样声明
并传递必要的变量
locals
{
boot_disk = [
{
source_image = var.bootSourceImage
disk_size_gb = var.bootDiskSizeGb
type = var.bootDiskType
auto_delete = var.bootDiskAutoDelete
boot = "true"
device_name="${var.machineName}-boot"
disk_type="PERSISTENT"
},
]
add_disk= [
{
source_image = var.bootSourceImage
disk_size_gb = var.disk1DiskSizeGb
type=var.disk1DiskType
device_name=var.disk1DiskName
disk_type="PERSISTENT"
auto_delete=var.disk1DiskAutoDelete
boot="false"
}
]
}
all_disks=concat(local.boot_disk,local.add_disk) //i concatenate them
我需要在创建的磁盘上附加一个策略,所以我使用这个块
resource "google_compute_disk_resource_policy_attachment" "attached-disk" {
//Here i need to loop through all_disk
for_each=local.all_disk.boot=false?current_disk:[] //From the all_disks i need to filter if this not boot disk then get the value ex. all_disk.boot=false then return the disk to for_each
}
resource "google_compute_disk_resource_policy_attachment" "boot-disk" {
//Here i need to loop through all_disk
for_each=local.all_disk.boot=true?current_disk:[] //From the all_disks i need to filter if this is boot disk then get the value like all_disk.boot=true
}
如何使用for_each遍历all_disks并根据启动值返回当前磁盘?
【问题讨论】:
标签: terraform