Terraform 多循环
Terraform multi for loops
我需要在 tf.for 循环中使用多个 for 循环。这是我的代码
data "oci_identity_availability_domains" "ad" {
compartment_id = var.tenancy_ocid
}
output ad {
value = data.oci_identity_availability_domains.ad.availability_domains[*].name
}
广告输出:
广告 = [
“阿比:PHX-AD-1”,
“阿比:PHX-AD-2”,
“阿比:PHX-AD-3”,
]
我的json文件:
{
"compute" : [
{
"service" : "standard-e3-core-ad-count",
"value" : 10000
},
{
"service" : "standard-e3-memory-count",
"value" : 10000
}
]
}
我需要在availability_domain
中使用广告
local.info = jsondecode(file("${path.module}/info.json"))
data "oci_limits_limit_values" "count" {
for_each = {
for index, value in flatten([
for name, value in local.info : [
for i in value : { name : name, service : i.serice }
]
]) : index => value
}
compartment_id = var.tenancy_ocid
service_name = each.value.service_name
name = each.value.limit_name
**availability_domain = { I need to run this for all 3 AD}**
}
我卡在 availability_domain 上了。该值将为 1 或 3。它基于 data.oci_identity_availability_domains.ad.availability_domains[*].name。有什么建议吗?
据我所知,您可以创建一个扁平化数据结构,例如:
locals {
ad_info_product = merge([
for ad in data.oci_identity_availability_domains.ad:
{
for compute in local.info["compute"]:
"${ad}-${compute.service}" => {
ad = ad
service = compute["service"]
limit = compute["value"]
}
}
]...) # please do NOT remove the dots
}
然后:
data "oci_limits_limit_values" "count" {
for_each = local.ad_info_product
compartment_id = var.tenancy_ocid
service_name = each.value["service"]
name = each.value["limit"]
availability_domain = each.value["ad"]
}
我需要在 tf.for 循环中使用多个 for 循环。这是我的代码
data "oci_identity_availability_domains" "ad" {
compartment_id = var.tenancy_ocid
}
output ad {
value = data.oci_identity_availability_domains.ad.availability_domains[*].name
}
广告输出: 广告 = [ “阿比:PHX-AD-1”, “阿比:PHX-AD-2”, “阿比:PHX-AD-3”, ]
我的json文件:
{
"compute" : [
{
"service" : "standard-e3-core-ad-count",
"value" : 10000
},
{
"service" : "standard-e3-memory-count",
"value" : 10000
}
]
}
我需要在availability_domain
中使用广告 local.info = jsondecode(file("${path.module}/info.json"))
data "oci_limits_limit_values" "count" {
for_each = {
for index, value in flatten([
for name, value in local.info : [
for i in value : { name : name, service : i.serice }
]
]) : index => value
}
compartment_id = var.tenancy_ocid
service_name = each.value.service_name
name = each.value.limit_name
**availability_domain = { I need to run this for all 3 AD}**
}
我卡在 availability_domain 上了。该值将为 1 或 3。它基于 data.oci_identity_availability_domains.ad.availability_domains[*].name。有什么建议吗?
据我所知,您可以创建一个扁平化数据结构,例如:
locals {
ad_info_product = merge([
for ad in data.oci_identity_availability_domains.ad:
{
for compute in local.info["compute"]:
"${ad}-${compute.service}" => {
ad = ad
service = compute["service"]
limit = compute["value"]
}
}
]...) # please do NOT remove the dots
}
然后:
data "oci_limits_limit_values" "count" {
for_each = local.ad_info_product
compartment_id = var.tenancy_ocid
service_name = each.value["service"]
name = each.value["limit"]
availability_domain = each.value["ad"]
}