Skip to content

Commit e761dce

Browse files
authored
feat: allow passing roles to created Workload Identity service account (#708)
1 parent 68e8eec commit e761dce

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

modules/workload-identity/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ module "my-app-workload-identity" {
2020
name = "my-application-name"
2121
namespace = "default"
2222
project_id = "my-gcp-project-name"
23+
roles = ["roles/storage.Admin", "roles/compute.Admin"]
2324
}
2425
```
2526

@@ -75,6 +76,7 @@ module "my-app-workload-identity" {
7576
| name | Name for both service accounts. The GCP SA will be truncated to the first 30 chars if necessary. | string | n/a | yes |
7677
| namespace | Namespace for k8s service account | string | `"default"` | no |
7778
| project\_id | GCP project ID | string | n/a | yes |
79+
| roles | (optional) A list of roles to be added to the created Service account | list(string) | `<list>` | no |
7880
| use\_existing\_k8s\_sa | Use an existing kubernetes service account instead of creating one | bool | `"false"` | no |
7981

8082
## Outputs

modules/workload-identity/main.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,12 @@ resource "google_service_account_iam_member" "main" {
6464
role = "roles/iam.workloadIdentityUser"
6565
member = local.k8s_sa_gcp_derived_name
6666
}
67+
68+
69+
resource "google_project_iam_member" "workload_identity_sa_bindings" {
70+
for_each = toset(var.roles)
71+
72+
project = var.project_id
73+
role = each.value
74+
member = "serviceAccount:${google_service_account.cluster_service_account.email}"
75+
}

modules/workload-identity/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,9 @@ variable "automount_service_account_token" {
5959
default = false
6060
type = bool
6161
}
62+
63+
variable "roles" {
64+
type = list(string)
65+
default = []
66+
description = "(optional) A list of roles to be added to the created Service account"
67+
}

0 commit comments

Comments
 (0)