Skip to content

Commit b387621

Browse files
authored
feat: workload-identity: Allow passing Google Service Account display_name and description (#1834)
1 parent c63aa4f commit b387621

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

modules/workload-identity/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ already bear the `"iam.gke.io/gcp-service-account"` annotation.
103103
| annotate\_k8s\_sa | Annotate the kubernetes service account with 'iam.gke.io/gcp-service-account' annotation. Valid in cases when an existing SA is used. | `bool` | `true` | no |
104104
| automount\_service\_account\_token | Enable automatic mounting of the service account token | `bool` | `false` | no |
105105
| cluster\_name | Cluster name. Required if using existing KSA. | `string` | `""` | no |
106+
| gcp\_sa\_description | The Service Google service account desciption; if null, will be left out | `string` | `null` | no |
107+
| gcp\_sa\_display\_name | The Google service account display name; if null, a default string will be used | `string` | `null` | no |
106108
| gcp\_sa\_name | Name for the Google service account; overrides `var.name`. | `string` | `null` | no |
107109
| impersonate\_service\_account | An optional service account to impersonate for gcloud commands. If this service account is not specified, the module will use Application Default Credentials. | `string` | `""` | no |
108110
| k8s\_sa\_name | Name for the Kubernetes service account; overrides `var.name`. `cluster_name` and `location` must be set when this input is specified. | `string` | `null` | no |

modules/workload-identity/main.tf

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ resource "google_service_account" "cluster_service_account" {
4343
count = var.use_existing_gcp_sa ? 0 : 1
4444

4545
account_id = local.gcp_given_name
46-
display_name = substr("GCP SA bound to K8S SA ${local.k8s_sa_project_id}[${local.k8s_given_name}]", 0, 100)
46+
display_name = coalesce(var.gcp_sa_display_name, substr("GCP SA bound to K8S SA ${local.k8s_sa_project_id}[${local.k8s_given_name}]", 0, 100))
47+
description = var.gcp_sa_description
4748
project = var.project_id
4849
}
4950

modules/workload-identity/variables.tf

+24
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,27 @@ variable "additional_projects" {
113113
type = map(list(string))
114114
default = {}
115115
}
116+
117+
variable "gcp_sa_display_name" {
118+
description = "The Google service account display name; if null, a default string will be used"
119+
type = string
120+
nullable = true
121+
default = null
122+
123+
validation {
124+
condition = var.gcp_sa_display_name == null ? true : length(var.gcp_sa_display_name) <= 100
125+
error_message = "The Google service account display name must be at most 100 characters"
126+
}
127+
}
128+
129+
variable "gcp_sa_description" {
130+
description = "The Service Google service account desciption; if null, will be left out"
131+
type = string
132+
nullable = true
133+
default = null
134+
135+
validation {
136+
condition = var.gcp_sa_description == null ? true : length(var.gcp_sa_description) <= 256
137+
error_message = "The Google service account description must be at most 256 characters"
138+
}
139+
}

0 commit comments

Comments
 (0)