Skip to content

Commit baefc13

Browse files
committed
fix: add a new variable for service account name
1 parent b6b2ebc commit baefc13

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

autogen/main/sa.tf.tmpl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,17 @@
1717
{{ autogeneration_note }}
1818

1919
locals {
20+
service_account_list = compact(
21+
concat(
22+
google_service_account.cluster_service_account.*.email,
23+
["dummy"],
24+
),
25+
)
2026
service_account_default_name = "tf-gke-${substr(var.name, 0, min(15, length(var.name)))}-${random_string.cluster_service_account_suffix.result}"
27+
service_account_name = var.service_account_name == "" ? local.service_account_default_name : var.service_account_name
28+
2129
// 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
22-
service_account = (var.service_account == "" || var.service_account == "create") && var.create_service_account ? local.service_account_default_name : var.service_account
30+
service_account = (var.service_account == "" || var.service_account == "create") && var.create_service_account ? local.service_account_list[0] : var.service_account
2331

2432
registry_projects_list = length(var.registry_project_ids) == 0 ? [var.project_id] : var.registry_project_ids
2533
}
@@ -34,7 +42,7 @@ resource "random_string" "cluster_service_account_suffix" {
3442
resource "google_service_account" "cluster_service_account" {
3543
count = var.create_service_account ? 1 : 0
3644
project = var.project_id
37-
account_id = local.service_account
45+
account_id = local.service_account_name
3846
display_name = "Terraform-managed service account for cluster ${var.name}"
3947
}
4048

autogen/main/variables.tf.tmpl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,12 @@ variable "service_account" {
383383
default = ""
384384
}
385385

386+
variable "service_account_name" {
387+
type = string
388+
description = "The name of the service account that will be created if create_service_account is true."
389+
default = ""
390+
}
391+
386392
variable "issue_client_certificate" {
387393
type = bool
388394
description = "Issues a client certificate to authenticate to the cluster endpoint. To maximize the security of your cluster, leave this option disabled. Client certificates don't automatically rotate and aren't easily revocable. WARNING: changing this after cluster creation is destructive!"

0 commit comments

Comments
 (0)