Skip to content

Commit a7cfe92

Browse files
authored
fix(acm)!: prevent conflicts in IAM binding (#1576)
1 parent 23e9c96 commit a7cfe92

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

modules/acm/creds.tf

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
locals {
1818
# GCP service account ids must be <= 30 chars matching regex ^[a-z](?:[-a-z0-9]{4,28}[a-z0-9])$
1919
service_account_name = trimsuffix(substr(var.metrics_gcp_sa_name, 0, 30), "-")
20+
21+
iam_ksa_binding_members = var.create_metrics_gcp_sa ? [
22+
var.enable_config_sync ? "config-management-monitoring/default" : null,
23+
var.enable_policy_controller ? "gatekeeper-system/gatekeeper-admin" : null,
24+
] : []
2025
}
2126

2227
resource "tls_private_key" "k8sop_creds" {
@@ -33,22 +38,14 @@ resource "time_sleep" "wait_acm" {
3338
create_duration = "300s"
3439
}
3540

36-
resource "google_service_account_iam_binding" "config-management-monitoring-iam" {
37-
count = var.enable_config_sync && var.create_metrics_gcp_sa ? 1 : 0
38-
service_account_id = google_service_account.acm_metrics_writer_sa[0].name
39-
role = "roles/iam.workloadIdentityUser"
40-
41-
members = ["serviceAccount:${var.project_id}.svc.id.goog[config-management-monitoring/default]"]
42-
43-
depends_on = [google_gke_hub_feature_membership.main]
44-
}
45-
46-
resource "google_service_account_iam_binding" "gatekeeper-system-iam" {
47-
count = var.enable_policy_controller && var.create_metrics_gcp_sa ? 1 : 0
41+
resource "google_service_account_iam_binding" "ksa_iam" {
42+
count = length(local.iam_ksa_binding_members) > 0 ? 1 : 0
4843
service_account_id = google_service_account.acm_metrics_writer_sa[0].name
4944
role = "roles/iam.workloadIdentityUser"
5045

51-
members = ["serviceAccount:${var.project_id}.svc.id.goog[gatekeeper-system/gatekeeper-admin]"]
46+
members = [
47+
for ksa in local.iam_ksa_binding_members : "serviceAccount:${var.project_id}.svc.id.goog[${ksa}]"
48+
]
5249

5350
depends_on = [google_gke_hub_feature_membership.main]
5451
}

0 commit comments

Comments
 (0)