From 13ec49fc386b31a9d1221ee7f689cb08eadc6eb2 Mon Sep 17 00:00:00 2001 From: Bharath KKB Date: Wed, 8 Mar 2023 20:11:42 -0600 Subject: [PATCH] fix: workaround for import issue when SA is unknown (#795) Co-authored-by: Andrew Peabody --- modules/core_project_factory/main.tf | 2 +- modules/core_project_factory/outputs.tf | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/core_project_factory/main.tf b/modules/core_project_factory/main.tf index 3715a2a4..3917419c 100644 --- a/modules/core_project_factory/main.tf +++ b/modules/core_project_factory/main.tf @@ -44,7 +44,7 @@ locals { ) : local.base_project_id s_account_fmt = var.create_project_sa ? format( "serviceAccount:%s", - google_service_account.default_service_account[0].email, + try(google_service_account.default_service_account[0].email, ""), ) : "" api_s_account = format( "%s@cloudservices.gserviceaccount.com", diff --git a/modules/core_project_factory/outputs.tf b/modules/core_project_factory/outputs.tf index 1ec33640..b3d8a930 100644 --- a/modules/core_project_factory/outputs.tf +++ b/modules/core_project_factory/outputs.tf @@ -37,27 +37,27 @@ output "project_number" { } output "service_account_id" { - value = var.create_project_sa ? google_service_account.default_service_account[0].account_id : "" + value = var.create_project_sa ? try(google_service_account.default_service_account[0].account_id, "") : "" description = "The id of the default service account" } output "service_account_display_name" { - value = var.create_project_sa ? google_service_account.default_service_account[0].display_name : "" + value = var.create_project_sa ? try(google_service_account.default_service_account[0].display_name, "") : "" description = "The display name of the default service account" } output "service_account_email" { - value = var.create_project_sa ? google_service_account.default_service_account[0].email : "" + value = var.create_project_sa ? try(google_service_account.default_service_account[0].email, "") : "" description = "The email of the default service account" } output "service_account_name" { - value = var.create_project_sa ? google_service_account.default_service_account[0].name : "" + value = var.create_project_sa ? try(google_service_account.default_service_account[0].name, "") : "" description = "The fully-qualified name of the default service account" } output "service_account_unique_id" { - value = var.create_project_sa ? google_service_account.default_service_account[0].unique_id : "" + value = var.create_project_sa ? try(google_service_account.default_service_account[0].unique_id, "") : "" description = "The unique id of the default service account" }