I have tried a couple of ways to iterate through a map in yaml but each results i keep getting errors ex: local.settings is object with # attributes .
to start with here is my yaml and locals setup
config:
params:
server:
host: 127.0.0.1
port: 8080
media:
name: foobar
type: html
s3:
bucket: foobarbucket
uploadFolder: folderfoobar
type:
public: false
email:
to: noreply@foobar.com
locals {
settings = yamldecode(file("test.yaml"))
}
module "store_write" {
source = "cloudposse/ssm-parameter-store/aws"
for_each = local.settings.variables
parameter_write = [
{
name = "/settings/${each.key}(i need each param key name ex: server)/${each.key.NEXTKET}(then the following key name after ex:host)"
value = "${each.key.value}(that keys value, ex: 127.0.0.1)"
type = "String"
overwrite = "true"
description = "Terraform deployed param: ${local.app_name} ${each.key}"
}
]
}
now of course i get an output of whats decoded from the yaml file, but every for loop i try wont work. at this point i cant even find 1 that is clean enough to paste here. i dont think i can achieve what i need IF sometimes the key names ex: s3 or email change over time right?
also notice sometimes i might get 3 levels,
config:
params:
s3:
bucket: foobarbucket
uploadFolder: folderfoobar
type:
public: false
I got a bit further in trying the following and had to edit the yaml file a bit. BUT now im getting duplicates
locals {
params = yamldecode(file("./test.yaml"))["app"]
folder_project_apis = flatten([
for fk, param in local.params : [
for pk, config in param.params : [
for lk, name in config : [
for vk, value in config : {
key1 = fk
key2 = pk
key3 = lk
value = value
}
]
]
]
])
}
using new yaml structure
app:
testing: #fk
display_name: "Folder A"
parent:
params:
server: #pk
host:
- 127.0.0.1
port:
- 3000
s3:
layout:
- "uploads"
image:
- "total"
outputs
> local.folder_project_apis
[
{
"key1" = "testing"
"key2" = "s3"
"key3" = "image"
"value" = [
"total",
]
},
{
"key1" = "testing"
"key2" = "s3"
"key3" = "image"
"value" = [
"uploads",
]
},
{
"key1" = "testing"
"key2" = "s3"
"key3" = "layout"
"value" = [
"total",
]
},
{
"key1" = "testing"
"key2" = "s3"
"key3" = "layout"
"value" = [
"uploads",
]
},
{
"key1" = "testing"
"key2" = "server"
"key3" = "host"
"value" = [
"127.0.0.1",
]
},
{
"key1" = "testing"
"key2" = "server"
"key3" = "host"
"value" = [
3000,
]
},
{
"key1" = "testing"
"key2" = "server"
"key3" = "port"
"value" = [
"127.0.0.1",
]
},
{
"key1" = "testing"
"key2" = "server"
"key3" = "port"
"value" = [
3000,
]
},
]