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

feat: Workload Identity module, to bind roles in various projects for the service account created #1574

Merged
merged 5 commits into from
Apr 4, 2023
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
4 changes: 2 additions & 2 deletions modules/workload-identity/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,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"]
roles = ["my-gcp-project-name-1=>roles/storage.admin", "my-gcp-project-name-2=>roles/compute.admin"]
}
```

Expand Down Expand Up @@ -109,7 +109,7 @@ already bear the `"iam.gke.io/gcp-service-account"` annotation.
| 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 the Kubernetes service account | `string` | `"default"` | no |
| project\_id | GCP project ID | `string` | n/a | yes |
| roles | A list of roles to be added to the created service account | `list(string)` | `[]` | no |
| roles | A list of roles to be added to the created service account for specific projects | `list(string)` | `[]` | no |
| use\_existing\_context | An optional flag to use local kubectl config context. | `bool` | `false` | no |
| use\_existing\_gcp\_sa | Use an existing Google service account instead of creating one | `bool` | `false` | no |
| use\_existing\_k8s\_sa | Use an existing kubernetes service account instead of creating one | `bool` | `false` | no |
Expand Down
4 changes: 2 additions & 2 deletions modules/workload-identity/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ resource "google_service_account_iam_member" "main" {
resource "google_project_iam_member" "workload_identity_sa_bindings" {
for_each = toset(var.roles)

project = var.project_id
role = each.value
project = element(split("=>", each.value), 0)
role = element(split("=>", each.value), 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend using a map(list(string)) rather than string parsing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed with your point.

member = local.gcp_sa_fqn
}
2 changes: 1 addition & 1 deletion modules/workload-identity/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ variable "automount_service_account_token" {
}

variable "roles" {
description = "A list of roles to be added to the created service account"
description = "A list of roles to be added to the created service account for specific projects"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently this would be a breaking change, if possible can we make this backward compatible.

A quick thought might be add a new (optional) map(list(string)) of additional projects=>[roles], and leave the existing roles for just var.project_id?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes are made as mentioned. Pls review

type = list(string)
default = []
}
Expand Down