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.
18
18
19
19
``` hcl
20
20
module "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"]}
26
28
}
27
29
```
28
30
@@ -97,6 +99,7 @@ already bear the `"iam.gke.io/gcp-service-account"` annotation.
97
99
98
100
| Name | Description | Type | Default | Required |
99
101
| ------| -------------| ------| ---------| :--------:|
102
+ | additional\_ projects | A list of roles to be added to the created service account for additional projects | ` map(list(string)) ` | ` {} ` | no |
100
103
| 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 |
101
104
| automount\_ service\_ account\_ token | Enable automatic mounting of the service account token | ` bool ` | ` false ` | no |
102
105
| 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 {
28
28
29
29
k8s_sa_project_id = var. k8s_sa_project_id != null ? var. k8s_sa_project_id : var. project_id
30
30
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 }]]))
31
33
}
32
34
33
35
data "google_service_account" "cluster_service_account" {
@@ -89,3 +91,11 @@ resource "google_project_iam_member" "workload_identity_sa_bindings" {
89
91
role = each. value
90
92
member = local. gcp_sa_fqn
91
93
}
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" {
107
107
type = list (any )
108
108
default = []
109
109
}
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