Skip to content

Commit

Permalink
refactor so that map outputs are kept, and new list outputs are added
Browse files Browse the repository at this point in the history
ludoo committed Aug 14, 2019
1 parent 573a1e8 commit df3777e
Showing 4 changed files with 17 additions and 7 deletions.
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -9,9 +9,9 @@ and this project adheres to

## [Unreleased]

- **Backwards-incompatible change:** outputs for multiple resource now return lists instead of maps, so that the same order of the input variable is kept.
- Added new outputs to expose the base resources.
- Refactored the `iam_emails` output to use the new `for` expression, fixing issues with `formatlist` and `zipmap` in Terraform 0.12.
- Added new `service_account` and `service_accounts` outputs for single and multi user use that expose the base resources, now possible with Terraform 0.12.
- Added new `emails_list` and `iam_emails_list` outputs that return lists, and are guaranteed to keep the same ordering for resources as the map type outputs.
- Refactored the formatted list generation for the `iam_emails` and new `iam_emails_list` outputs to use the new `for` expression, fixing issues with `formatlist` and `zipmap` in Terraform 0.12.
- Refactored and simplified the `keys` template and output using the new splat syntax.

## [1.0.0] - 2019-07-26
4 changes: 2 additions & 2 deletions examples/multiple_service_accounts/outputs.tf
Original file line number Diff line number Diff line change
@@ -16,12 +16,12 @@

output "emails" {
description = "The service account emails."
value = module.service_accounts.emails
value = module.service_accounts.emails_list
}

output "iam_emails" {
description = "The service account IAM-format emails."
value = module.service_accounts.iam_emails
value = module.service_accounts.iam_emails_list
}

output "keys" {
1 change: 1 addition & 0 deletions main.tf
Original file line number Diff line number Diff line change
@@ -19,6 +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 != ""
iam_emails = [for s in google_service_account.service_accounts : "serviceAccount:${s.email}"]
}

# create service accounts
13 changes: 11 additions & 2 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -41,10 +41,20 @@ output "service_accounts" {

output "emails" {
description = "Service account emails."
value = google_service_account.service_accounts[*].email
value = zipmap(var.names, google_service_account.service_accounts[*].email)
}

output "iam_emails" {
description = "IAM-format service account emails."
value = zipmap(var.names, local.iam_emails)
}

output "emails_list" {
description = "Service account emails."
value = google_service_account.service_accounts[*].email
}

output "iam_emails_list" {
description = "IAM-format service account emails."
value = [for s in google_service_account.service_accounts : "serviceAccount:${s.email}"]
}
@@ -63,4 +73,3 @@ output "keys" {
sensitive = true
value = zipmap(var.names, data.template_file.keys[*].rendered)
}

0 comments on commit df3777e

Please sign in to comment.