Skip to content

Commit aee12e7

Browse files
fix: trim trailing dash from gcp SA name (#1243)
As per noted regexp, the service account name cannot end with a dash. This can happen when the name is over 30 characters long and so a substring is extracted, but the 30th character happens to be a dash.
1 parent f67dbc7 commit aee12e7

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

modules/workload-identity/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
*/
1616

1717
locals {
18-
# GCP service account ids must be < 30 chars matching regex ^[a-z](?:[-a-z0-9]{4,28}[a-z0-9])$
18+
# GCP service account ids must be <= 30 chars matching regex ^[a-z](?:[-a-z0-9]{4,28}[a-z0-9])$
1919
# KSAs do not have this naming restriction.
20-
gcp_given_name = var.gcp_sa_name != null ? var.gcp_sa_name : substr(var.name, 0, 30)
20+
gcp_given_name = var.gcp_sa_name != null ? var.gcp_sa_name : trimsuffix(substr(var.name, 0, 30), "-")
2121
gcp_sa_email = var.use_existing_gcp_sa ? data.google_service_account.cluster_service_account[0].email : google_service_account.cluster_service_account[0].email
2222
gcp_sa_fqn = "serviceAccount:${local.gcp_sa_email}"
2323

0 commit comments

Comments
 (0)