Skip to content

Commit

Permalink
fix: skip service account random_string when not needed (#2024)
Browse files Browse the repository at this point in the history
Co-authored-by: Andrew Peabody <[email protected]>
  • Loading branch information
Bo98 and apeabody authored Aug 5, 2024
1 parent 177166a commit be88d19
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 10 deletions.
3 changes: 2 additions & 1 deletion autogen/main/sa.tf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ 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_default_name = var.create_service_account && var.service_account_name == "" ? "tf-gke-${substr(var.name, 0, min(15, length(var.name)))}-${random_string.cluster_service_account_suffix[0].result}" : null

// 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 @@ -32,6 +32,7 @@ locals {
}

resource "random_string" "cluster_service_account_suffix" {
count = var.create_service_account && var.service_account_name == "" ? 1 : 0
upper = false
lower = true
special = false
Expand Down
3 changes: 2 additions & 1 deletion modules/beta-autopilot-private-cluster/sa.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ 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_default_name = var.create_service_account && var.service_account_name == "" ? "tf-gke-${substr(var.name, 0, min(15, length(var.name)))}-${random_string.cluster_service_account_suffix[0].result}" : null

// 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 @@ -32,6 +32,7 @@ locals {
}

resource "random_string" "cluster_service_account_suffix" {
count = var.create_service_account && var.service_account_name == "" ? 1 : 0
upper = false
lower = true
special = false
Expand Down
3 changes: 2 additions & 1 deletion modules/beta-autopilot-public-cluster/sa.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ 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_default_name = var.create_service_account && var.service_account_name == "" ? "tf-gke-${substr(var.name, 0, min(15, length(var.name)))}-${random_string.cluster_service_account_suffix[0].result}" : null

// 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 @@ -32,6 +32,7 @@ locals {
}

resource "random_string" "cluster_service_account_suffix" {
count = var.create_service_account && var.service_account_name == "" ? 1 : 0
upper = false
lower = true
special = false
Expand Down
3 changes: 2 additions & 1 deletion modules/beta-private-cluster-update-variant/sa.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ 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_default_name = var.create_service_account && var.service_account_name == "" ? "tf-gke-${substr(var.name, 0, min(15, length(var.name)))}-${random_string.cluster_service_account_suffix[0].result}" : null

// 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 @@ -32,6 +32,7 @@ locals {
}

resource "random_string" "cluster_service_account_suffix" {
count = var.create_service_account && var.service_account_name == "" ? 1 : 0
upper = false
lower = true
special = false
Expand Down
3 changes: 2 additions & 1 deletion modules/beta-private-cluster/sa.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ 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_default_name = var.create_service_account && var.service_account_name == "" ? "tf-gke-${substr(var.name, 0, min(15, length(var.name)))}-${random_string.cluster_service_account_suffix[0].result}" : null

// 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 @@ -32,6 +32,7 @@ locals {
}

resource "random_string" "cluster_service_account_suffix" {
count = var.create_service_account && var.service_account_name == "" ? 1 : 0
upper = false
lower = true
special = false
Expand Down
3 changes: 2 additions & 1 deletion modules/beta-public-cluster-update-variant/sa.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ 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_default_name = var.create_service_account && var.service_account_name == "" ? "tf-gke-${substr(var.name, 0, min(15, length(var.name)))}-${random_string.cluster_service_account_suffix[0].result}" : null

// 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 @@ -32,6 +32,7 @@ locals {
}

resource "random_string" "cluster_service_account_suffix" {
count = var.create_service_account && var.service_account_name == "" ? 1 : 0
upper = false
lower = true
special = false
Expand Down
3 changes: 2 additions & 1 deletion modules/beta-public-cluster/sa.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ 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_default_name = var.create_service_account && var.service_account_name == "" ? "tf-gke-${substr(var.name, 0, min(15, length(var.name)))}-${random_string.cluster_service_account_suffix[0].result}" : null

// 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 @@ -32,6 +32,7 @@ locals {
}

resource "random_string" "cluster_service_account_suffix" {
count = var.create_service_account && var.service_account_name == "" ? 1 : 0
upper = false
lower = true
special = false
Expand Down
3 changes: 2 additions & 1 deletion modules/private-cluster-update-variant/sa.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ 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_default_name = var.create_service_account && var.service_account_name == "" ? "tf-gke-${substr(var.name, 0, min(15, length(var.name)))}-${random_string.cluster_service_account_suffix[0].result}" : null

// 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 @@ -32,6 +32,7 @@ locals {
}

resource "random_string" "cluster_service_account_suffix" {
count = var.create_service_account && var.service_account_name == "" ? 1 : 0
upper = false
lower = true
special = false
Expand Down
3 changes: 2 additions & 1 deletion modules/private-cluster/sa.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ 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_default_name = var.create_service_account && var.service_account_name == "" ? "tf-gke-${substr(var.name, 0, min(15, length(var.name)))}-${random_string.cluster_service_account_suffix[0].result}" : null

// 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 @@ -32,6 +32,7 @@ locals {
}

resource "random_string" "cluster_service_account_suffix" {
count = var.create_service_account && var.service_account_name == "" ? 1 : 0
upper = false
lower = true
special = false
Expand Down
3 changes: 2 additions & 1 deletion sa.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ 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_default_name = var.create_service_account && var.service_account_name == "" ? "tf-gke-${substr(var.name, 0, min(15, length(var.name)))}-${random_string.cluster_service_account_suffix[0].result}" : null

// 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 @@ -32,6 +32,7 @@ locals {
}

resource "random_string" "cluster_service_account_suffix" {
count = var.create_service_account && var.service_account_name == "" ? 1 : 0
upper = false
lower = true
special = false
Expand Down

0 comments on commit be88d19

Please sign in to comment.