I would like to process each value in a nested map for dynamic “port”
How I can substitution all keys?
app_01 - has three ports
app_02 - has one ports
If is use for_each = local.k8_manifest.app_01.containerport
it works well
but for_each = local.k8_manifest[*].containerport
- doesn’t work
locals {
...
k8_manifest = {
"app_01" = {
...
restartPolicy = "Always"
containerport = [
{
port = "9093"
protocol = "TCP"
},
{
port = "9094"
protocol = "TCP"
},
{
port = "9096"
protocol = "TCP"
}
]
...
},
"app_02" = {
...
restartPolicy = "Always"
containerport = [
{
port = "9097"
protocol = "TCP"
},
}
resource "kubernetes_deployment" "victoriametrics" {
for_each = local.k8_manifest
metadata {
...
spec {
dns_policy = "ClusterFirst"
termination_grace_period_seconds = 30
restart_policy = "Always"
container {
image = "111111111111.dkr.ecr.us-east-2.amazonaws.com/alertmanager:0.23.0"
name = "app_01"
dynamic "port" {
for_each = local.k8_manifest.app_01.containerport
#for_each = local.k8_manifest
content {
container_port = port.value.port
protocol = port.value.protocol
}
}
...
p.s.This code isn’t completed yet.