Skip to content

Commit 0225458

Browse files
author
Jacob Ferriero
authored
fix: Shorten GSA account_id if necessary (#666)
1 parent c6aea6b commit 0225458

File tree

4 files changed

+5
-56
lines changed

4 files changed

+5
-56
lines changed

modules/workload-identity/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ module "my-app-workload-identity" {
7272
| cluster\_name | Cluster name. Required if using existing KSA. | string | `""` | no |
7373
| k8s\_sa\_name | Name for the existing Kubernetes service account | string | `"null"` | no |
7474
| location | Cluster location (region if regional cluster, zone if zonal cluster). Required if using existing KSA. | string | `""` | no |
75-
| name | Name for both service accounts | string | n/a | yes |
75+
| name | Name for both service accounts. The GCP SA will be truncated to the first 30 chars if necessary. | string | n/a | yes |
7676
| namespace | Namespace for k8s service account | string | `"default"` | no |
7777
| project\_id | GCP project ID | string | n/a | yes |
7878
| use\_existing\_k8s\_sa | Use an existing kubernetes service account instead of creating one | bool | `"false"` | no |

modules/workload-identity/main.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ locals {
2525
}
2626

2727
resource "google_service_account" "cluster_service_account" {
28-
account_id = var.name
28+
# GCP service account ids must be < 30 chars matching regex ^[a-z](?:[-a-z0-9]{4,28}[a-z0-9])$
29+
# KSA do not have this naming restriction.
30+
account_id = substr(var.name, 0, 30)
2931
display_name = substr("GCP SA bound to K8S SA ${local.k8s_given_name}", 0, 100)
3032
project = var.project_id
3133
}

modules/workload-identity/scripts/kubectl_wrapper.sh

Lines changed: 0 additions & 53 deletions
This file was deleted.

modules/workload-identity/variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717
variable "name" {
18-
description = "Name for both service accounts"
18+
description = "Name for both service accounts. The GCP SA will be truncated to the first 30 chars if necessary."
1919
type = string
2020
}
2121

0 commit comments

Comments
 (0)