Skip to content

Commit 76d779c

Browse files
flozzoneapeabody
andauthored
feat: Add create_ignore_already_exists to workload_identity (#2142)
Co-authored-by: Andrew Peabody <[email protected]>
1 parent 375d27c commit 76d779c

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

modules/workload-identity/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ Error: Get "http://localhost/api/v1/namespaces/default/serviceaccounts/your-serv
148148
| 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 |
149149
| automount\_service\_account\_token | Enable automatic mounting of the service account token | `bool` | `false` | no |
150150
| cluster\_name | Cluster name. Required if using existing KSA. | `string` | `""` | no |
151+
| gcp\_sa\_create\_ignore\_already\_exists | If set to true, skip service account creation if a service account with the same email already exists. | `bool` | `null` | no |
151152
| gcp\_sa\_description | The Service Google service account desciption; if null, will be left out | `string` | `null` | no |
152153
| gcp\_sa\_display\_name | The Google service account display name; if null, a default string will be used | `string` | `null` | no |
153154
| gcp\_sa\_name | Name for the Google service account; overrides `var.name`. | `string` | `null` | no |

modules/workload-identity/main.tf

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@ data "google_service_account" "cluster_service_account" {
4242
resource "google_service_account" "cluster_service_account" {
4343
count = var.use_existing_gcp_sa ? 0 : 1
4444

45-
account_id = local.gcp_given_name
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
48-
project = var.project_id
45+
account_id = local.gcp_given_name
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
48+
project = var.project_id
49+
create_ignore_already_exists = var.gcp_sa_create_ignore_already_exists
4950
}
5051

5152
resource "kubernetes_service_account" "main" {

modules/workload-identity/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,9 @@ variable "gcp_sa_description" {
137137
error_message = "The Google service account description must be at most 256 characters"
138138
}
139139
}
140+
141+
variable "gcp_sa_create_ignore_already_exists" {
142+
description = "If set to true, skip service account creation if a service account with the same email already exists."
143+
type = bool
144+
default = null
145+
}

0 commit comments

Comments
 (0)