Skip to content

Commit

Permalink
feat: Add create_ignore_already_exists to workload_identity (#2142)
Browse files Browse the repository at this point in the history
Co-authored-by: Andrew Peabody <[email protected]>
  • Loading branch information
flozzone and apeabody authored Oct 25, 2024
1 parent 375d27c commit 76d779c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions modules/workload-identity/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ Error: Get "http://localhost/api/v1/namespaces/default/serviceaccounts/your-serv
| 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 |
| automount\_service\_account\_token | Enable automatic mounting of the service account token | `bool` | `false` | no |
| cluster\_name | Cluster name. Required if using existing KSA. | `string` | `""` | no |
| 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 |
| gcp\_sa\_description | The Service Google service account desciption; if null, will be left out | `string` | `null` | no |
| gcp\_sa\_display\_name | The Google service account display name; if null, a default string will be used | `string` | `null` | no |
| gcp\_sa\_name | Name for the Google service account; overrides `var.name`. | `string` | `null` | no |
Expand Down
9 changes: 5 additions & 4 deletions modules/workload-identity/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ data "google_service_account" "cluster_service_account" {
resource "google_service_account" "cluster_service_account" {
count = var.use_existing_gcp_sa ? 0 : 1

account_id = local.gcp_given_name
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))
description = var.gcp_sa_description
project = var.project_id
account_id = local.gcp_given_name
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))
description = var.gcp_sa_description
project = var.project_id
create_ignore_already_exists = var.gcp_sa_create_ignore_already_exists
}

resource "kubernetes_service_account" "main" {
Expand Down
6 changes: 6 additions & 0 deletions modules/workload-identity/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,9 @@ variable "gcp_sa_description" {
error_message = "The Google service account description must be at most 256 characters"
}
}

variable "gcp_sa_create_ignore_already_exists" {
description = "If set to true, skip service account creation if a service account with the same email already exists."
type = bool
default = null
}

0 comments on commit 76d779c

Please sign in to comment.