From b6b2ebce74554d1bbe1585cd95363c222be31456 Mon Sep 17 00:00:00 2001 From: Thomas Griseau Date: Mon, 17 Apr 2023 10:37:58 +0200 Subject: [PATCH] fix: use provided service_account_name if available --- autogen/main/sa.tf.tmpl | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/autogen/main/sa.tf.tmpl b/autogen/main/sa.tf.tmpl index 16aaf5287f..f5a02ef8c6 100644 --- a/autogen/main/sa.tf.tmpl +++ b/autogen/main/sa.tf.tmpl @@ -17,14 +17,9 @@ {{ autogeneration_note }} locals { - service_account_list = compact( - concat( - google_service_account.cluster_service_account.*.email, - ["dummy"], - ), - ) + service_account_default_name = "tf-gke-${substr(var.name, 0, min(15, length(var.name)))}-${random_string.cluster_service_account_suffix.result}" // if user set var.service_account it will be used even if var.create_service_account==true, so service account will be created but not used - service_account = (var.service_account == "" || var.service_account == "create") && var.create_service_account ? local.service_account_list[0] : var.service_account + service_account = (var.service_account == "" || var.service_account == "create") && var.create_service_account ? local.service_account_default_name : var.service_account registry_projects_list = length(var.registry_project_ids) == 0 ? [var.project_id] : var.registry_project_ids } @@ -39,7 +34,7 @@ resource "random_string" "cluster_service_account_suffix" { resource "google_service_account" "cluster_service_account" { count = var.create_service_account ? 1 : 0 project = var.project_id - account_id = "tf-gke-${substr(var.name, 0, min(15, length(var.name)))}-${random_string.cluster_service_account_suffix.result}" + account_id = local.service_account display_name = "Terraform-managed service account for cluster ${var.name}" }