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 1 commit
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
1 change: 1 addition & 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
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" {
count = length(var.roles)
bharathkkb marked this conversation as resolved.
Show resolved Hide resolved

project = var.project_id
role = var.roles[count.index]
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"
}