Skip to content

Commit

Permalink
fix: use provided service_account_name if available
Browse files Browse the repository at this point in the history
  • Loading branch information
griseau committed Apr 17, 2023
1 parent db51271 commit b6b2ebc
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions autogen/main/sa.tf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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}"
}

Expand Down

0 comments on commit b6b2ebc

Please sign in to comment.