File tree Expand file tree Collapse file tree 3 files changed +24
-5
lines changed
modules/workload-identity Expand file tree Collapse file tree 3 files changed +24
-5
lines changed Original file line number Diff line number Diff line change @@ -18,11 +18,13 @@ Kubernetes accounts.
1818
1919``` hcl
2020module "my-app-workload-identity" {
21- source = "terraform-google-modules/kubernetes-engine/google//modules/workload-identity"
22- name = "my-application-name"
23- namespace = "default"
24- project_id = "my-gcp-project-name"
25- roles = ["roles/storage.admin", "roles/compute.admin"]
21+ source = "terraform-google-modules/kubernetes-engine/google//modules/workload-identity"
22+ name = "my-application-name"
23+ namespace = "default"
24+ project_id = "my-gcp-project-name"
25+ roles = ["roles/storage.admin", "roles/compute.admin"]
26+ additional_projects = {"my-gcp-project-name1" : ["roles/storage.admin", "roles/compute.admin"],
27+ "my-gcp-project-name2" : ["roles/storage.admin", "roles/compute.admin"]}
2628}
2729```
2830
@@ -97,6 +99,7 @@ already bear the `"iam.gke.io/gcp-service-account"` annotation.
9799
98100| Name | Description | Type | Default | Required |
99101| ------| -------------| ------| ---------| :--------:|
102+ | additional\_ projects | A list of roles to be added to the created service account for additional projects | ` map(list(string)) ` | ` {} ` | no |
100103| 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 |
101104| automount\_ service\_ account\_ token | Enable automatic mounting of the service account token | ` bool ` | ` false ` | no |
102105| cluster\_ name | Cluster name. Required if using existing KSA. | ` string ` | ` "" ` | no |
Original file line number Diff line number Diff line change @@ -28,6 +28,8 @@ locals {
2828
2929 k8s_sa_project_id = var. k8s_sa_project_id != null ? var. k8s_sa_project_id : var. project_id
3030 k8s_sa_gcp_derived_name = " serviceAccount:${ local . k8s_sa_project_id } .svc.id.goog[${ var . namespace } /${ local . output_k8s_name } ]"
31+
32+ sa_binding_additional_project = distinct (flatten ([for project , roles in var . additional_projects : [for role in roles : { project_id = project, role_name = role }]]))
3133}
3234
3335data "google_service_account" "cluster_service_account" {
@@ -89,3 +91,11 @@ resource "google_project_iam_member" "workload_identity_sa_bindings" {
8991 role = each. value
9092 member = local. gcp_sa_fqn
9193}
94+
95+ resource "google_project_iam_member" "workload_identity_sa_bindings_additional_projects" {
96+ for_each = { for entry in local . sa_binding_additional_project : " ${ entry . project_id } .${ entry . role_name } " => entry }
97+
98+ project = each. value . project_id
99+ role = each. value . role_name
100+ member = local. gcp_sa_fqn
101+ }
Original file line number Diff line number Diff line change @@ -107,3 +107,9 @@ variable "module_depends_on" {
107107 type = list (any )
108108 default = []
109109}
110+
111+ variable "additional_projects" {
112+ description = " A list of roles to be added to the created service account for additional projects"
113+ type = map (list (string ))
114+ default = {}
115+ }
You can’t perform that action at this time.
0 commit comments