【发布时间】:2022-01-11 13:25:54
【问题描述】:
我想从下面显示的 yaml 生成一个 terraform 配置,它将键 el2-dev 和 el2-shared-dev 设置为标签,并将列表 public_subnets 和 private_subnets 的值分别设置为 cidr_block。
aws:
el2-dev:
public_subnets:
- "10.44.1.0/27"
- "10.44.2.32/27"
- "10.44.3.64/27"
private_subnets:
- "10.44.4.96/27"
- "10.44.5.128/27"
- "10.44.6.160/27"
el2-shared-dev:
public_subnets:
- "10.44.7.0/27"
- "10.44.8.32/27"
- "10.44.9.64/27"
private_subnets:
- "10.44.10.96/27"
- "10.44.11.128/27"
- "10.44.12.160/27"
我正在使用这种方法,但没有有效的结果。
locals {
accounts = flatten([
for profile_name, blocks in var.aws : [
for record in blocks : {
record = record
profile_name = profile_name
}
]
])
}
resource "aws_subnet" "main" {
for_each = { for entry in local.accounts : sort(entry.profile_name) => entry }
cidr_block = tolist(local.cidr_blocks)
vpc_id = aws_vpc.main.id
tags = {
Name = flatten([each.value.record])
}
}
【问题讨论】: