From 4fab404c2f63abcd5070b922edd024e24d8294b9 Mon Sep 17 00:00:00 2001 From: Julliano Goncalves Date: Thu, 30 May 2024 12:22:06 -0300 Subject: [PATCH] feat: Adding extra permissions to the cluster's default service account (#1943) Signed-off-by: Julliano Goncalves --- autogen/main/sa.tf.tmpl | 14 ++++++++++++++ modules/beta-autopilot-private-cluster/sa.tf | 14 ++++++++++++++ modules/beta-autopilot-public-cluster/sa.tf | 14 ++++++++++++++ modules/beta-private-cluster-update-variant/sa.tf | 14 ++++++++++++++ modules/beta-private-cluster/sa.tf | 14 ++++++++++++++ modules/beta-public-cluster-update-variant/sa.tf | 14 ++++++++++++++ modules/beta-public-cluster/sa.tf | 14 ++++++++++++++ modules/private-cluster-update-variant/sa.tf | 14 ++++++++++++++ modules/private-cluster/sa.tf | 14 ++++++++++++++ sa.tf | 14 ++++++++++++++ 10 files changed, 140 insertions(+) diff --git a/autogen/main/sa.tf.tmpl b/autogen/main/sa.tf.tmpl index a775fbe6af..f38e3a8687 100644 --- a/autogen/main/sa.tf.tmpl +++ b/autogen/main/sa.tf.tmpl @@ -52,6 +52,20 @@ resource "google_project_iam_member" "cluster_service_account-nodeService_accoun member = google_service_account.cluster_service_account[0].member } +resource "google_project_iam_member" "cluster_service_account-metric_writer" { + count = var.create_service_account ? 1 : 0 + project = google_service_account.cluster_service_account[0].project + role = "roles/monitoring.metricWriter" + member = google_service_account.cluster_service_account[0].member +} + +resource "google_project_iam_member" "cluster_service_account-resourceMetadata-writer" { + count = var.create_service_account ? 1 : 0 + project = google_service_account.cluster_service_account[0].project + role = "roles/stackdriver.resourceMetadata.writer" + member = google_service_account.cluster_service_account[0].member +} + resource "google_project_iam_member" "cluster_service_account-gcr" { for_each = var.create_service_account && var.grant_registry_access ? toset(local.registry_projects_list) : [] project = each.key diff --git a/modules/beta-autopilot-private-cluster/sa.tf b/modules/beta-autopilot-private-cluster/sa.tf index 6c6e1f663b..fe36dadd32 100644 --- a/modules/beta-autopilot-private-cluster/sa.tf +++ b/modules/beta-autopilot-private-cluster/sa.tf @@ -52,6 +52,20 @@ resource "google_project_iam_member" "cluster_service_account-nodeService_accoun member = google_service_account.cluster_service_account[0].member } +resource "google_project_iam_member" "cluster_service_account-metric_writer" { + count = var.create_service_account ? 1 : 0 + project = google_service_account.cluster_service_account[0].project + role = "roles/monitoring.metricWriter" + member = google_service_account.cluster_service_account[0].member +} + +resource "google_project_iam_member" "cluster_service_account-resourceMetadata-writer" { + count = var.create_service_account ? 1 : 0 + project = google_service_account.cluster_service_account[0].project + role = "roles/stackdriver.resourceMetadata.writer" + member = google_service_account.cluster_service_account[0].member +} + resource "google_project_iam_member" "cluster_service_account-gcr" { for_each = var.create_service_account && var.grant_registry_access ? toset(local.registry_projects_list) : [] project = each.key diff --git a/modules/beta-autopilot-public-cluster/sa.tf b/modules/beta-autopilot-public-cluster/sa.tf index 6c6e1f663b..fe36dadd32 100644 --- a/modules/beta-autopilot-public-cluster/sa.tf +++ b/modules/beta-autopilot-public-cluster/sa.tf @@ -52,6 +52,20 @@ resource "google_project_iam_member" "cluster_service_account-nodeService_accoun member = google_service_account.cluster_service_account[0].member } +resource "google_project_iam_member" "cluster_service_account-metric_writer" { + count = var.create_service_account ? 1 : 0 + project = google_service_account.cluster_service_account[0].project + role = "roles/monitoring.metricWriter" + member = google_service_account.cluster_service_account[0].member +} + +resource "google_project_iam_member" "cluster_service_account-resourceMetadata-writer" { + count = var.create_service_account ? 1 : 0 + project = google_service_account.cluster_service_account[0].project + role = "roles/stackdriver.resourceMetadata.writer" + member = google_service_account.cluster_service_account[0].member +} + resource "google_project_iam_member" "cluster_service_account-gcr" { for_each = var.create_service_account && var.grant_registry_access ? toset(local.registry_projects_list) : [] project = each.key diff --git a/modules/beta-private-cluster-update-variant/sa.tf b/modules/beta-private-cluster-update-variant/sa.tf index 6c6e1f663b..fe36dadd32 100644 --- a/modules/beta-private-cluster-update-variant/sa.tf +++ b/modules/beta-private-cluster-update-variant/sa.tf @@ -52,6 +52,20 @@ resource "google_project_iam_member" "cluster_service_account-nodeService_accoun member = google_service_account.cluster_service_account[0].member } +resource "google_project_iam_member" "cluster_service_account-metric_writer" { + count = var.create_service_account ? 1 : 0 + project = google_service_account.cluster_service_account[0].project + role = "roles/monitoring.metricWriter" + member = google_service_account.cluster_service_account[0].member +} + +resource "google_project_iam_member" "cluster_service_account-resourceMetadata-writer" { + count = var.create_service_account ? 1 : 0 + project = google_service_account.cluster_service_account[0].project + role = "roles/stackdriver.resourceMetadata.writer" + member = google_service_account.cluster_service_account[0].member +} + resource "google_project_iam_member" "cluster_service_account-gcr" { for_each = var.create_service_account && var.grant_registry_access ? toset(local.registry_projects_list) : [] project = each.key diff --git a/modules/beta-private-cluster/sa.tf b/modules/beta-private-cluster/sa.tf index 6c6e1f663b..fe36dadd32 100644 --- a/modules/beta-private-cluster/sa.tf +++ b/modules/beta-private-cluster/sa.tf @@ -52,6 +52,20 @@ resource "google_project_iam_member" "cluster_service_account-nodeService_accoun member = google_service_account.cluster_service_account[0].member } +resource "google_project_iam_member" "cluster_service_account-metric_writer" { + count = var.create_service_account ? 1 : 0 + project = google_service_account.cluster_service_account[0].project + role = "roles/monitoring.metricWriter" + member = google_service_account.cluster_service_account[0].member +} + +resource "google_project_iam_member" "cluster_service_account-resourceMetadata-writer" { + count = var.create_service_account ? 1 : 0 + project = google_service_account.cluster_service_account[0].project + role = "roles/stackdriver.resourceMetadata.writer" + member = google_service_account.cluster_service_account[0].member +} + resource "google_project_iam_member" "cluster_service_account-gcr" { for_each = var.create_service_account && var.grant_registry_access ? toset(local.registry_projects_list) : [] project = each.key diff --git a/modules/beta-public-cluster-update-variant/sa.tf b/modules/beta-public-cluster-update-variant/sa.tf index 6c6e1f663b..fe36dadd32 100644 --- a/modules/beta-public-cluster-update-variant/sa.tf +++ b/modules/beta-public-cluster-update-variant/sa.tf @@ -52,6 +52,20 @@ resource "google_project_iam_member" "cluster_service_account-nodeService_accoun member = google_service_account.cluster_service_account[0].member } +resource "google_project_iam_member" "cluster_service_account-metric_writer" { + count = var.create_service_account ? 1 : 0 + project = google_service_account.cluster_service_account[0].project + role = "roles/monitoring.metricWriter" + member = google_service_account.cluster_service_account[0].member +} + +resource "google_project_iam_member" "cluster_service_account-resourceMetadata-writer" { + count = var.create_service_account ? 1 : 0 + project = google_service_account.cluster_service_account[0].project + role = "roles/stackdriver.resourceMetadata.writer" + member = google_service_account.cluster_service_account[0].member +} + resource "google_project_iam_member" "cluster_service_account-gcr" { for_each = var.create_service_account && var.grant_registry_access ? toset(local.registry_projects_list) : [] project = each.key diff --git a/modules/beta-public-cluster/sa.tf b/modules/beta-public-cluster/sa.tf index 6c6e1f663b..fe36dadd32 100644 --- a/modules/beta-public-cluster/sa.tf +++ b/modules/beta-public-cluster/sa.tf @@ -52,6 +52,20 @@ resource "google_project_iam_member" "cluster_service_account-nodeService_accoun member = google_service_account.cluster_service_account[0].member } +resource "google_project_iam_member" "cluster_service_account-metric_writer" { + count = var.create_service_account ? 1 : 0 + project = google_service_account.cluster_service_account[0].project + role = "roles/monitoring.metricWriter" + member = google_service_account.cluster_service_account[0].member +} + +resource "google_project_iam_member" "cluster_service_account-resourceMetadata-writer" { + count = var.create_service_account ? 1 : 0 + project = google_service_account.cluster_service_account[0].project + role = "roles/stackdriver.resourceMetadata.writer" + member = google_service_account.cluster_service_account[0].member +} + resource "google_project_iam_member" "cluster_service_account-gcr" { for_each = var.create_service_account && var.grant_registry_access ? toset(local.registry_projects_list) : [] project = each.key diff --git a/modules/private-cluster-update-variant/sa.tf b/modules/private-cluster-update-variant/sa.tf index 6f89899bee..da1930c7b3 100644 --- a/modules/private-cluster-update-variant/sa.tf +++ b/modules/private-cluster-update-variant/sa.tf @@ -52,6 +52,20 @@ resource "google_project_iam_member" "cluster_service_account-nodeService_accoun member = google_service_account.cluster_service_account[0].member } +resource "google_project_iam_member" "cluster_service_account-metric_writer" { + count = var.create_service_account ? 1 : 0 + project = google_service_account.cluster_service_account[0].project + role = "roles/monitoring.metricWriter" + member = google_service_account.cluster_service_account[0].member +} + +resource "google_project_iam_member" "cluster_service_account-resourceMetadata-writer" { + count = var.create_service_account ? 1 : 0 + project = google_service_account.cluster_service_account[0].project + role = "roles/stackdriver.resourceMetadata.writer" + member = google_service_account.cluster_service_account[0].member +} + resource "google_project_iam_member" "cluster_service_account-gcr" { for_each = var.create_service_account && var.grant_registry_access ? toset(local.registry_projects_list) : [] project = each.key diff --git a/modules/private-cluster/sa.tf b/modules/private-cluster/sa.tf index 6f89899bee..da1930c7b3 100644 --- a/modules/private-cluster/sa.tf +++ b/modules/private-cluster/sa.tf @@ -52,6 +52,20 @@ resource "google_project_iam_member" "cluster_service_account-nodeService_accoun member = google_service_account.cluster_service_account[0].member } +resource "google_project_iam_member" "cluster_service_account-metric_writer" { + count = var.create_service_account ? 1 : 0 + project = google_service_account.cluster_service_account[0].project + role = "roles/monitoring.metricWriter" + member = google_service_account.cluster_service_account[0].member +} + +resource "google_project_iam_member" "cluster_service_account-resourceMetadata-writer" { + count = var.create_service_account ? 1 : 0 + project = google_service_account.cluster_service_account[0].project + role = "roles/stackdriver.resourceMetadata.writer" + member = google_service_account.cluster_service_account[0].member +} + resource "google_project_iam_member" "cluster_service_account-gcr" { for_each = var.create_service_account && var.grant_registry_access ? toset(local.registry_projects_list) : [] project = each.key diff --git a/sa.tf b/sa.tf index 6f89899bee..da1930c7b3 100644 --- a/sa.tf +++ b/sa.tf @@ -52,6 +52,20 @@ resource "google_project_iam_member" "cluster_service_account-nodeService_accoun member = google_service_account.cluster_service_account[0].member } +resource "google_project_iam_member" "cluster_service_account-metric_writer" { + count = var.create_service_account ? 1 : 0 + project = google_service_account.cluster_service_account[0].project + role = "roles/monitoring.metricWriter" + member = google_service_account.cluster_service_account[0].member +} + +resource "google_project_iam_member" "cluster_service_account-resourceMetadata-writer" { + count = var.create_service_account ? 1 : 0 + project = google_service_account.cluster_service_account[0].project + role = "roles/stackdriver.resourceMetadata.writer" + member = google_service_account.cluster_service_account[0].member +} + resource "google_project_iam_member" "cluster_service_account-gcr" { for_each = var.create_service_account && var.grant_registry_access ? toset(local.registry_projects_list) : [] project = each.key