build and use local map of username to dbname

This commit is contained in:
Florian Heuer 2025-12-16 13:51:14 +01:00
parent d361fa8da9
commit 010ac595c1
Signed by: florian.heuer
GPG key ID: 40A4312733654662

View file

@ -3,6 +3,14 @@ output "postgres_instance_id" {
value = stackit_postgresflex_instance.this.instance_id
}
locals {
# Build a map: username => db_name
user_to_db = {
for db in var.postgres_databases :
db.user_name => db.db_name
}
}
# Postgres Credential Output
output "postgres_credentials" {
value = {
@ -12,7 +20,7 @@ output "postgres_credentials" {
username = u.username
password = u.password
port = u.port
db_name = stackit_postgresflex_database.this[u.username].name
db_name = stackit_postgresflex_database.this[local.user_to_db[u.username]].name
uri = u.uri
}
}