Skip to content

Commit f786995

Browse files
committed
add existing ksa to example
1 parent 824a180 commit f786995

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

examples/workload_identity/main.tf

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ module "gke" {
5353
]
5454
}
5555

56+
# example without existing KSA
5657
module "workload_identity" {
5758
source = "../../modules/workload-identity"
5859
project_id = var.project_id
@@ -61,5 +62,27 @@ module "workload_identity" {
6162
use_existing_k8s_sa = false
6263
}
6364

65+
66+
# example with existing KSA
67+
resource "kubernetes_service_account" "test" {
68+
metadata {
69+
name = "foo-ksa"
70+
}
71+
secret {
72+
name = "bar"
73+
}
74+
}
75+
76+
module "workload_identity_existing_ksa" {
77+
source = "../../modules/workload-identity"
78+
project_id = var.project_id
79+
name = "existing-${module.gke.name}"
80+
cluster_name = module.gke.name
81+
location = module.gke.location
82+
namespace = "default"
83+
use_existing_k8s_sa = true
84+
k8s_sa_name = kubernetes_service_account.test.metadata.0.name
85+
}
86+
6487
data "google_client_config" "default" {
6588
}

modules/workload-identity/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ module "annotate-sa" {
6969
create_cmd_body = "${local.cluster_endpoint} ${local.token} ${local.cluster_ca_certificate} kubectl annotate --overwrite sa -n ${local.output_k8s_namespace} ${local.k8s_given_name} iam.gke.io/gcp-service-account=${local.gcp_sa_email}"
7070

7171
destroy_cmd_entrypoint = "${path.module}/scripts/kubectl_wrapper.sh"
72-
destroy_cmd_body = "${local.cluster_endpoint} ${local.token} ${local.cluster_ca_certificate} kubectl annotate --overwrite sa -n ${local.output_k8s_namespace} ${local.k8s_given_name} iam.gke.io/gcp-service-account-"
72+
destroy_cmd_body = "${local.cluster_endpoint} ${local.token} ${local.cluster_ca_certificate} kubectl annotate sa -n ${local.output_k8s_namespace} ${local.k8s_given_name} iam.gke.io/gcp-service-account-"
7373
}
7474

7575
resource "google_service_account_iam_member" "main" {

0 commit comments

Comments
 (0)