Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workload Identity: allow passing roles to created service account #708

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions modules/workload-identity/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module "my-app-workload-identity" {
name = "my-application-name"
namespace = "default"
project_id = "my-gcp-project-name"
roles = ["roles/storage.Admin", "roles/compute.Admin"]
}
```

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

## Outputs
Expand Down
9 changes: 9 additions & 0 deletions modules/workload-identity/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,12 @@ resource "google_service_account_iam_member" "main" {
role = "roles/iam.workloadIdentityUser"
member = local.k8s_sa_gcp_derived_name
}


resource "google_project_iam_member" "workload_identity_sa_bindings" {
for_each = toset(var.roles)

project = var.project_id
role = each.value
member = "serviceAccount:${google_service_account.cluster_service_account.email}"
}
6 changes: 6 additions & 0 deletions modules/workload-identity/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,9 @@ variable "automount_service_account_token" {
default = false
type = bool
}

variable "roles" {
type = list(string)
default = []
description = "(optional) A list of roles to be added to the created Service account"
}