Skip to content

Commit cb0f7f0

Browse files
authored
fix: Output values directly from resource (#57)
1 parent 5afef97 commit cb0f7f0

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ locals {
1919
org_billing = var.grant_billing_role && var.billing_account_id == "" && var.org_id != ""
2020
prefix = var.prefix != "" ? "${var.prefix}-" : ""
2121
xpn = var.grant_xpn_roles && var.org_id != ""
22-
service_accounts_list = [for name in var.names : google_service_account.service_accounts[name]]
22+
service_accounts_list = [for account in google_service_account.service_accounts : account]
2323
emails_list = [for account in local.service_accounts_list : account.email]
2424
iam_emails_list = [for email in local.emails_list : "serviceAccount:${email}"]
2525
names = toset(var.names)

outputs.tf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@
1616

1717
output "service_account" {
1818
description = "Service account resource (for single use)."
19-
value = local.service_accounts_list[0]
19+
value = try(local.service_accounts_list[0], null)
2020
}
2121

2222
output "email" {
2323
description = "Service account email (for single use)."
24-
value = local.emails_list[0]
24+
value = try(local.emails_list[0], null)
2525
}
2626

2727
output "iam_email" {
2828
description = "IAM-format service account email (for single use)."
29-
value = local.iam_emails_list[0]
29+
value = try(local.iam_emails_list[0], null)
3030
}
3131

3232
output "key" {
@@ -47,12 +47,12 @@ output "service_accounts_map" {
4747

4848
output "emails" {
4949
description = "Service account emails by name."
50-
value = zipmap(var.names, local.emails_list)
50+
value = zipmap(local.service_accounts_list[*].name, local.emails_list)
5151
}
5252

5353
output "iam_emails" {
5454
description = "IAM-format service account emails by name."
55-
value = zipmap(var.names, local.iam_emails_list)
55+
value = zipmap(local.service_accounts_list[*].name, local.iam_emails_list)
5656
}
5757

5858
output "emails_list" {

0 commit comments

Comments
 (0)