From ad243cc575c56c4be12d9cd9e29ab23be361e241 Mon Sep 17 00:00:00 2001 From: Ludovico Magnocavallo Date: Sat, 9 Nov 2019 07:30:02 +0100 Subject: [PATCH 1/5] Make outputs work on names variable change --- main.tf | 3 ++- outputs.tf | 16 +++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/main.tf b/main.tf index 8bbc15a..1e1f04e 100644 --- a/main.tf +++ b/main.tf @@ -19,7 +19,8 @@ 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}"] + emails = [for account in google_service_account.service_accounts : account.email] + iam_emails = [for email in local.emails : "serviceAccount:${email}"] } # create service accounts diff --git a/outputs.tf b/outputs.tf index b742036..de2f62b 100644 --- a/outputs.tf +++ b/outputs.tf @@ -41,22 +41,26 @@ output "service_accounts" { output "emails" { description = "Service account emails." - value = zipmap(var.names, google_service_account.service_accounts[*].email) + value = zipmap(var.names, [ + for i in range(length(var.names)) : i > length(local.emails) - 1 ? "" : local.emails[i] + ]) } output "iam_emails" { description = "IAM-format service account emails." - value = zipmap(var.names, local.iam_emails) + value = zipmap(var.names, [ + for i in range(length(var.names)) : i > length(local.iam_emails) - 1 ? "" : local.iam_emails[i] + ]) } output "emails_list" { description = "Service account emails." - value = google_service_account.service_accounts[*].email + value = local.emails } output "iam_emails_list" { description = "IAM-format service account emails." - value = [for s in google_service_account.service_accounts : "serviceAccount:${s.email}"] + value = local.iam_emails } data "template_file" "keys" { @@ -71,5 +75,7 @@ data "template_file" "keys" { output "keys" { description = "Map of service account keys." sensitive = true - value = zipmap(var.names, data.template_file.keys[*].rendered) + value = zipmap(var.names, [ + for i in range(length(var.names)) : i > length(data.template_file.keys) ? "" : data.template_file.keys[*].rendered + ]) } From 8f45a5cddef090bd8ff01dd83def75506a97a2a9 Mon Sep 17 00:00:00 2001 From: Ludovico Magnocavallo Date: Sat, 9 Nov 2019 08:02:07 +0100 Subject: [PATCH 2/5] fix keys output --- outputs.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/outputs.tf b/outputs.tf index de2f62b..3a23649 100644 --- a/outputs.tf +++ b/outputs.tf @@ -76,6 +76,6 @@ output "keys" { description = "Map of service account keys." sensitive = true value = zipmap(var.names, [ - for i in range(length(var.names)) : i > length(data.template_file.keys) ? "" : data.template_file.keys[*].rendered + for i in range(length(var.names)) : i > length(data.template_file.keys) ? "" : data.template_file.keys[i].rendered ]) } From d11d11add2d427d5ae7b65d62ffe5ef40fa3bf44 Mon Sep 17 00:00:00 2001 From: Ludovico Magnocavallo Date: Sat, 9 Nov 2019 08:39:27 +0100 Subject: [PATCH 3/5] use simpler fix borrowed from folders module, as issue is only on item removal --- outputs.tf | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/outputs.tf b/outputs.tf index 3a23649..70dccca 100644 --- a/outputs.tf +++ b/outputs.tf @@ -41,16 +41,12 @@ output "service_accounts" { output "emails" { description = "Service account emails." - value = zipmap(var.names, [ - for i in range(length(var.names)) : i > length(local.emails) - 1 ? "" : local.emails[i] - ]) + value = zipmap(var.names, slice(local.emails, 0, length(var.names))) } output "iam_emails" { description = "IAM-format service account emails." - value = zipmap(var.names, [ - for i in range(length(var.names)) : i > length(local.iam_emails) - 1 ? "" : local.iam_emails[i] - ]) + value = zipmap(var.names, slice(local.iam_emails, 0, length(var.names))) } output "emails_list" { @@ -75,7 +71,8 @@ data "template_file" "keys" { output "keys" { description = "Map of service account keys." sensitive = true - value = zipmap(var.names, [ - for i in range(length(var.names)) : i > length(data.template_file.keys) ? "" : data.template_file.keys[i].rendered - ]) + value = zipmap( + var.names, + slice(data.template_file.keys[*].rendered, 0, length(var.names)) + ) } From 5f1602c49016da79d2e409becbc2c0afa71ca360 Mon Sep 17 00:00:00 2001 From: Ludovico Magnocavallo Date: Sat, 9 Nov 2019 08:41:36 +0100 Subject: [PATCH 4/5] add CODEOWNERS --- CODEOWNERS | 1 + 1 file changed, 1 insertion(+) create mode 100644 CODEOWNERS diff --git a/CODEOWNERS b/CODEOWNERS new file mode 100644 index 0000000..fa27914 --- /dev/null +++ b/CODEOWNERS @@ -0,0 +1 @@ +* @morgante @aaron-lane @ludoo @averbuks From 4ff2275d24baba4bea5c496847cbc6acdb6f73d8 Mon Sep 17 00:00:00 2001 From: Ludovico Magnocavallo Date: Sat, 9 Nov 2019 08:45:55 +0100 Subject: [PATCH 5/5] update CHANGELOG --- CHANGELOG.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ab60cc9..16b074a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,12 @@ and this project adheres to ## [Unreleased] +## [2.0.2] - 2019-10-09 + +### Fixed + +- Fix outputs on `names` variable element removal/change [#14] + ## [2.0.1] - 2019-09-13 ### Changed @@ -44,12 +50,16 @@ and this project adheres to - Initial release. [#1] -[Unreleased]: https://github.com/terraform-google-modules/terraform-google-service-accounts/compare/v2.0.0...HEAD +[Unreleased]: https://github.com/terraform-google-modules/terraform-google-service-accounts/compare/v2.0.2...HEAD +[2.0.2]: https://github.com/terraform-google-modules/terraform-google-service-accounts/compare/v2.0.1...v2.0.2 +[2.0.1]: https://github.com/terraform-google-modules/terraform-google-service-accounts/compare/v2.0.0...v2.0.1 [2.0.0]: https://github.com/terraform-google-modules/terraform-google-service-accounts/compare/v1.0.0...v2.0.0 [1.0.0]: https://github.com/terraform-google-modules/terraform-google-service-accounts/compare/v0.1.1...v1.0.0 [0.1.1]: https://github.com/terraform-google-modules/terraform-google-service-accounts/compare/v0.1.0...v0.1.1 [0.1.0]: https://github.com/terraform-google-modules/terraform-google-service-accounts/releases/tag/v0.1.0 +[#14]: https://github.com/terraform-google-modules/terraform-google-service-accounts/pull/14 +[#13]: https://github.com/terraform-google-modules/terraform-google-service-accounts/pull/13 [#9]: https://github.com/terraform-google-modules/terraform-google-service-accounts/pull/9 [#3]: https://github.com/terraform-google-modules/terraform-google-service-accounts/pull/3 [#1]: https://github.com/terraform-google-modules/terraform-google-service-accounts/pull/1