Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use provided service_account_name if available #1610

Merged
merged 4 commits into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion autogen/main/sa.tf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ locals {
["dummy"],
),
)
service_account_default_name = "tf-gke-${substr(var.name, 0, min(15, length(var.name)))}-${random_string.cluster_service_account_suffix.result}"
service_account_name = var.service_account_name == "" ? local.service_account_default_name : var.service_account_name

// 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

Expand All @@ -39,7 +42,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_name
griseau marked this conversation as resolved.
Show resolved Hide resolved
display_name = "Terraform-managed service account for cluster ${var.name}"
}

Expand Down
6 changes: 6 additions & 0 deletions autogen/main/variables.tf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,12 @@ variable "service_account" {
default = ""
}

variable "service_account_name" {
type = string
description = "The name of the service account that will be created if create_service_account is true."
default = ""
}

variable "issue_client_certificate" {
type = bool
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!"
Expand Down