From cb0f7f0e3a70956477bd275e1949461124a3f233 Mon Sep 17 00:00:00 2001 From: Wojciech Krysmann Date: Thu, 3 Feb 2022 14:35:09 -0800 Subject: [PATCH] fix: Output values directly from resource (#57) --- main.tf | 2 +- outputs.tf | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/main.tf b/main.tf index 79bfc0b..61376fd 100644 --- a/main.tf +++ b/main.tf @@ -19,7 +19,7 @@ locals { org_billing = var.grant_billing_role && var.billing_account_id == "" && var.org_id != "" prefix = var.prefix != "" ? "${var.prefix}-" : "" xpn = var.grant_xpn_roles && var.org_id != "" - service_accounts_list = [for name in var.names : google_service_account.service_accounts[name]] + service_accounts_list = [for account in google_service_account.service_accounts : account] emails_list = [for account in local.service_accounts_list : account.email] iam_emails_list = [for email in local.emails_list : "serviceAccount:${email}"] names = toset(var.names) diff --git a/outputs.tf b/outputs.tf index 7ae9307..35e2506 100644 --- a/outputs.tf +++ b/outputs.tf @@ -16,17 +16,17 @@ output "service_account" { description = "Service account resource (for single use)." - value = local.service_accounts_list[0] + value = try(local.service_accounts_list[0], null) } output "email" { description = "Service account email (for single use)." - value = local.emails_list[0] + value = try(local.emails_list[0], null) } output "iam_email" { description = "IAM-format service account email (for single use)." - value = local.iam_emails_list[0] + value = try(local.iam_emails_list[0], null) } output "key" { @@ -47,12 +47,12 @@ output "service_accounts_map" { output "emails" { description = "Service account emails by name." - value = zipmap(var.names, local.emails_list) + value = zipmap(local.service_accounts_list[*].name, local.emails_list) } output "iam_emails" { description = "IAM-format service account emails by name." - value = zipmap(var.names, local.iam_emails_list) + value = zipmap(local.service_accounts_list[*].name, local.iam_emails_list) } output "emails_list" {