Skip to content

Commit 4aad5e9

Browse files
samuelarogbonloapeabody
andauthoredJan 17, 2025··
feat: add support for custom monitoring metrics writer role (#2239)
Signed-off-by: samuelarogbonlo <sbayo971@gmail.com> Co-authored-by: Andrew Peabody <andrewpeabody@google.com>
1 parent 9a5aa01 commit 4aad5e9

File tree

30 files changed

+120
-10
lines changed

30 files changed

+120
-10
lines changed
 

‎README.md

+1
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ Then perform the following commands on the root folder:
212212
| monitoring\_enable\_observability\_metrics | Whether or not the advanced datapath metrics are enabled. | `bool` | `false` | no |
213213
| monitoring\_enable\_observability\_relay | Whether or not the advanced datapath relay is enabled. | `bool` | `false` | no |
214214
| monitoring\_enabled\_components | List of services to monitor: SYSTEM\_COMPONENTS, APISERVER, SCHEDULER, CONTROLLER\_MANAGER, STORAGE, HPA, POD, DAEMONSET, DEPLOYMENT, STATEFULSET, KUBELET, CADVISOR and DCGM. In beta provider, WORKLOADS is supported on top of those 12 values. (WORKLOADS is deprecated and removed in GKE 1.24.) KUBELET and CADVISOR are only supported in GKE 1.29.3-gke.1093000 and above. Empty list is default GKE configuration. | `list(string)` | `[]` | no |
215+
| monitoring\_metric\_writer\_role | The monitoring metrics writer role to assign to the GKE node service account | `string` | `"roles/monitoring.metricWriter"` | no |
215216
| monitoring\_service | The monitoring service that the cluster should write metrics to. Automatically send metrics from pods in the cluster to the Google Cloud Monitoring API. VM metrics will be collected by Google Compute Engine regardless of this setting Available options include monitoring.googleapis.com, monitoring.googleapis.com/kubernetes (beta) and none | `string` | `"monitoring.googleapis.com/kubernetes"` | no |
216217
| name | The name of the cluster (required) | `string` | n/a | yes |
217218
| network | The VPC network to host the cluster in (required) | `string` | n/a | yes |

‎autogen/main/sa.tf.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ resource "google_project_iam_member" "cluster_service_account_node_service_accou
5656
resource "google_project_iam_member" "cluster_service_account_metric_writer" {
5757
count = var.create_service_account ? 1 : 0
5858
project = google_service_account.cluster_service_account[0].project
59-
role = "roles/monitoring.metricWriter"
59+
role = var.monitoring_metric_writer_role
6060
member = google_service_account.cluster_service_account[0].member
6161
}
6262

‎autogen/main/variables.tf.tmpl

+10
Original file line numberDiff line numberDiff line change
@@ -1032,3 +1032,13 @@ variable "logging_variant" {
10321032
default = null
10331033
}
10341034
{% endif %}
1035+
1036+
variable "monitoring_metric_writer_role" {
1037+
description = "The monitoring metrics writer role to assign to the GKE node service account"
1038+
type = string
1039+
default = "roles/monitoring.metricWriter"
1040+
validation {
1041+
condition = can(regex("^(roles/[a-zA-Z0-9_.]+|projects/[a-zA-Z0-9-]+/roles/[a-zA-Z0-9_.]+)$", var.monitoring_metric_writer_role))
1042+
error_message = "The monitoring_metric_writer_role must be either a predefined role (roles/*) or a custom role (projects/*/roles/*)."
1043+
}
1044+
}

‎modules/beta-autopilot-private-cluster/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ Then perform the following commands on the root folder:
129129
| master\_global\_access\_enabled | Whether the cluster master is accessible globally (from any region) or only within the same region as the private endpoint. | `bool` | `true` | no |
130130
| master\_ipv4\_cidr\_block | (Optional) The IP range in CIDR notation to use for the hosted master network. | `string` | `null` | no |
131131
| monitoring\_enabled\_components | List of services to monitor: SYSTEM\_COMPONENTS, APISERVER, SCHEDULER, CONTROLLER\_MANAGER, STORAGE, HPA, POD, DAEMONSET, DEPLOYMENT, STATEFULSET, KUBELET, CADVISOR and DCGM. In beta provider, WORKLOADS is supported on top of those 12 values. (WORKLOADS is deprecated and removed in GKE 1.24.) KUBELET and CADVISOR are only supported in GKE 1.29.3-gke.1093000 and above. Empty list is default GKE configuration. | `list(string)` | `[]` | no |
132+
| monitoring\_metric\_writer\_role | The monitoring metrics writer role to assign to the GKE node service account | `string` | `"roles/monitoring.metricWriter"` | no |
132133
| name | The name of the cluster (required) | `string` | n/a | yes |
133134
| network | The VPC network to host the cluster in (required) | `string` | n/a | yes |
134135
| network\_project\_id | The project ID of the shared VPC's host (for shared vpc support) | `string` | `""` | no |

‎modules/beta-autopilot-private-cluster/sa.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ resource "google_project_iam_member" "cluster_service_account_node_service_accou
5656
resource "google_project_iam_member" "cluster_service_account_metric_writer" {
5757
count = var.create_service_account ? 1 : 0
5858
project = google_service_account.cluster_service_account[0].project
59-
role = "roles/monitoring.metricWriter"
59+
role = var.monitoring_metric_writer_role
6060
member = google_service_account.cluster_service_account[0].member
6161
}
6262

‎modules/beta-autopilot-private-cluster/variables.tf

+10
Original file line numberDiff line numberDiff line change
@@ -597,3 +597,13 @@ variable "logging_variant" {
597597
type = string
598598
default = null
599599
}
600+
601+
variable "monitoring_metric_writer_role" {
602+
description = "The monitoring metrics writer role to assign to the GKE node service account"
603+
type = string
604+
default = "roles/monitoring.metricWriter"
605+
validation {
606+
condition = can(regex("^(roles/[a-zA-Z0-9_.]+|projects/[a-zA-Z0-9-]+/roles/[a-zA-Z0-9_.]+)$", var.monitoring_metric_writer_role))
607+
error_message = "The monitoring_metric_writer_role must be either a predefined role (roles/*) or a custom role (projects/*/roles/*)."
608+
}
609+
}

‎modules/beta-autopilot-public-cluster/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ Then perform the following commands on the root folder:
119119
| maintenance\_start\_time | Time window specified for daily or recurring maintenance operations in RFC3339 format | `string` | `"05:00"` | no |
120120
| master\_authorized\_networks | List of master authorized networks. If none are provided, disallow external access (except the cluster node IPs, which GKE automatically whitelists). | `list(object({ cidr_block = string, display_name = string }))` | `[]` | no |
121121
| monitoring\_enabled\_components | List of services to monitor: SYSTEM\_COMPONENTS, APISERVER, SCHEDULER, CONTROLLER\_MANAGER, STORAGE, HPA, POD, DAEMONSET, DEPLOYMENT, STATEFULSET, KUBELET, CADVISOR and DCGM. In beta provider, WORKLOADS is supported on top of those 12 values. (WORKLOADS is deprecated and removed in GKE 1.24.) KUBELET and CADVISOR are only supported in GKE 1.29.3-gke.1093000 and above. Empty list is default GKE configuration. | `list(string)` | `[]` | no |
122+
| monitoring\_metric\_writer\_role | The monitoring metrics writer role to assign to the GKE node service account | `string` | `"roles/monitoring.metricWriter"` | no |
122123
| name | The name of the cluster (required) | `string` | n/a | yes |
123124
| network | The VPC network to host the cluster in (required) | `string` | n/a | yes |
124125
| network\_project\_id | The project ID of the shared VPC's host (for shared vpc support) | `string` | `""` | no |

‎modules/beta-autopilot-public-cluster/sa.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ resource "google_project_iam_member" "cluster_service_account_node_service_accou
5656
resource "google_project_iam_member" "cluster_service_account_metric_writer" {
5757
count = var.create_service_account ? 1 : 0
5858
project = google_service_account.cluster_service_account[0].project
59-
role = "roles/monitoring.metricWriter"
59+
role = var.monitoring_metric_writer_role
6060
member = google_service_account.cluster_service_account[0].member
6161
}
6262

‎modules/beta-autopilot-public-cluster/variables.tf

+10
Original file line numberDiff line numberDiff line change
@@ -561,3 +561,13 @@ variable "logging_variant" {
561561
type = string
562562
default = null
563563
}
564+
565+
variable "monitoring_metric_writer_role" {
566+
description = "The monitoring metrics writer role to assign to the GKE node service account"
567+
type = string
568+
default = "roles/monitoring.metricWriter"
569+
validation {
570+
condition = can(regex("^(roles/[a-zA-Z0-9_.]+|projects/[a-zA-Z0-9-]+/roles/[a-zA-Z0-9_.]+)$", var.monitoring_metric_writer_role))
571+
error_message = "The monitoring_metric_writer_role must be either a predefined role (roles/*) or a custom role (projects/*/roles/*)."
572+
}
573+
}

‎modules/beta-private-cluster-update-variant/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ Then perform the following commands on the root folder:
255255
| monitoring\_enable\_observability\_metrics | Whether or not the advanced datapath metrics are enabled. | `bool` | `false` | no |
256256
| monitoring\_enable\_observability\_relay | Whether or not the advanced datapath relay is enabled. | `bool` | `false` | no |
257257
| monitoring\_enabled\_components | List of services to monitor: SYSTEM\_COMPONENTS, APISERVER, SCHEDULER, CONTROLLER\_MANAGER, STORAGE, HPA, POD, DAEMONSET, DEPLOYMENT, STATEFULSET, KUBELET, CADVISOR and DCGM. In beta provider, WORKLOADS is supported on top of those 12 values. (WORKLOADS is deprecated and removed in GKE 1.24.) KUBELET and CADVISOR are only supported in GKE 1.29.3-gke.1093000 and above. Empty list is default GKE configuration. | `list(string)` | `[]` | no |
258+
| monitoring\_metric\_writer\_role | The monitoring metrics writer role to assign to the GKE node service account | `string` | `"roles/monitoring.metricWriter"` | no |
258259
| monitoring\_service | The monitoring service that the cluster should write metrics to. Automatically send metrics from pods in the cluster to the Google Cloud Monitoring API. VM metrics will be collected by Google Compute Engine regardless of this setting Available options include monitoring.googleapis.com, monitoring.googleapis.com/kubernetes (beta) and none | `string` | `"monitoring.googleapis.com/kubernetes"` | no |
259260
| name | The name of the cluster (required) | `string` | n/a | yes |
260261
| network | The VPC network to host the cluster in (required) | `string` | n/a | yes |

‎modules/beta-private-cluster-update-variant/sa.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ resource "google_project_iam_member" "cluster_service_account_node_service_accou
5656
resource "google_project_iam_member" "cluster_service_account_metric_writer" {
5757
count = var.create_service_account ? 1 : 0
5858
project = google_service_account.cluster_service_account[0].project
59-
role = "roles/monitoring.metricWriter"
59+
role = var.monitoring_metric_writer_role
6060
member = google_service_account.cluster_service_account[0].member
6161
}
6262

‎modules/beta-private-cluster-update-variant/variables.tf

+10
Original file line numberDiff line numberDiff line change
@@ -968,3 +968,13 @@ variable "fleet_project_grant_service_agent" {
968968
type = bool
969969
default = false
970970
}
971+
972+
variable "monitoring_metric_writer_role" {
973+
description = "The monitoring metrics writer role to assign to the GKE node service account"
974+
type = string
975+
default = "roles/monitoring.metricWriter"
976+
validation {
977+
condition = can(regex("^(roles/[a-zA-Z0-9_.]+|projects/[a-zA-Z0-9-]+/roles/[a-zA-Z0-9_.]+)$", var.monitoring_metric_writer_role))
978+
error_message = "The monitoring_metric_writer_role must be either a predefined role (roles/*) or a custom role (projects/*/roles/*)."
979+
}
980+
}

‎modules/beta-private-cluster/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ Then perform the following commands on the root folder:
233233
| monitoring\_enable\_observability\_metrics | Whether or not the advanced datapath metrics are enabled. | `bool` | `false` | no |
234234
| monitoring\_enable\_observability\_relay | Whether or not the advanced datapath relay is enabled. | `bool` | `false` | no |
235235
| monitoring\_enabled\_components | List of services to monitor: SYSTEM\_COMPONENTS, APISERVER, SCHEDULER, CONTROLLER\_MANAGER, STORAGE, HPA, POD, DAEMONSET, DEPLOYMENT, STATEFULSET, KUBELET, CADVISOR and DCGM. In beta provider, WORKLOADS is supported on top of those 12 values. (WORKLOADS is deprecated and removed in GKE 1.24.) KUBELET and CADVISOR are only supported in GKE 1.29.3-gke.1093000 and above. Empty list is default GKE configuration. | `list(string)` | `[]` | no |
236+
| monitoring\_metric\_writer\_role | The monitoring metrics writer role to assign to the GKE node service account | `string` | `"roles/monitoring.metricWriter"` | no |
236237
| monitoring\_service | The monitoring service that the cluster should write metrics to. Automatically send metrics from pods in the cluster to the Google Cloud Monitoring API. VM metrics will be collected by Google Compute Engine regardless of this setting Available options include monitoring.googleapis.com, monitoring.googleapis.com/kubernetes (beta) and none | `string` | `"monitoring.googleapis.com/kubernetes"` | no |
237238
| name | The name of the cluster (required) | `string` | n/a | yes |
238239
| network | The VPC network to host the cluster in (required) | `string` | n/a | yes |

‎modules/beta-private-cluster/sa.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ resource "google_project_iam_member" "cluster_service_account_node_service_accou
5656
resource "google_project_iam_member" "cluster_service_account_metric_writer" {
5757
count = var.create_service_account ? 1 : 0
5858
project = google_service_account.cluster_service_account[0].project
59-
role = "roles/monitoring.metricWriter"
59+
role = var.monitoring_metric_writer_role
6060
member = google_service_account.cluster_service_account[0].member
6161
}
6262

‎modules/beta-private-cluster/variables.tf

+10
Original file line numberDiff line numberDiff line change
@@ -968,3 +968,13 @@ variable "fleet_project_grant_service_agent" {
968968
type = bool
969969
default = false
970970
}
971+
972+
variable "monitoring_metric_writer_role" {
973+
description = "The monitoring metrics writer role to assign to the GKE node service account"
974+
type = string
975+
default = "roles/monitoring.metricWriter"
976+
validation {
977+
condition = can(regex("^(roles/[a-zA-Z0-9_.]+|projects/[a-zA-Z0-9-]+/roles/[a-zA-Z0-9_.]+)$", var.monitoring_metric_writer_role))
978+
error_message = "The monitoring_metric_writer_role must be either a predefined role (roles/*) or a custom role (projects/*/roles/*)."
979+
}
980+
}

‎modules/beta-public-cluster-update-variant/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ Then perform the following commands on the root folder:
245245
| monitoring\_enable\_observability\_metrics | Whether or not the advanced datapath metrics are enabled. | `bool` | `false` | no |
246246
| monitoring\_enable\_observability\_relay | Whether or not the advanced datapath relay is enabled. | `bool` | `false` | no |
247247
| monitoring\_enabled\_components | List of services to monitor: SYSTEM\_COMPONENTS, APISERVER, SCHEDULER, CONTROLLER\_MANAGER, STORAGE, HPA, POD, DAEMONSET, DEPLOYMENT, STATEFULSET, KUBELET, CADVISOR and DCGM. In beta provider, WORKLOADS is supported on top of those 12 values. (WORKLOADS is deprecated and removed in GKE 1.24.) KUBELET and CADVISOR are only supported in GKE 1.29.3-gke.1093000 and above. Empty list is default GKE configuration. | `list(string)` | `[]` | no |
248+
| monitoring\_metric\_writer\_role | The monitoring metrics writer role to assign to the GKE node service account | `string` | `"roles/monitoring.metricWriter"` | no |
248249
| monitoring\_service | The monitoring service that the cluster should write metrics to. Automatically send metrics from pods in the cluster to the Google Cloud Monitoring API. VM metrics will be collected by Google Compute Engine regardless of this setting Available options include monitoring.googleapis.com, monitoring.googleapis.com/kubernetes (beta) and none | `string` | `"monitoring.googleapis.com/kubernetes"` | no |
249250
| name | The name of the cluster (required) | `string` | n/a | yes |
250251
| network | The VPC network to host the cluster in (required) | `string` | n/a | yes |

‎modules/beta-public-cluster-update-variant/sa.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ resource "google_project_iam_member" "cluster_service_account_node_service_accou
5656
resource "google_project_iam_member" "cluster_service_account_metric_writer" {
5757
count = var.create_service_account ? 1 : 0
5858
project = google_service_account.cluster_service_account[0].project
59-
role = "roles/monitoring.metricWriter"
59+
role = var.monitoring_metric_writer_role
6060
member = google_service_account.cluster_service_account[0].member
6161
}
6262

‎modules/beta-public-cluster-update-variant/variables.tf

+10
Original file line numberDiff line numberDiff line change
@@ -932,3 +932,13 @@ variable "fleet_project_grant_service_agent" {
932932
type = bool
933933
default = false
934934
}
935+
936+
variable "monitoring_metric_writer_role" {
937+
description = "The monitoring metrics writer role to assign to the GKE node service account"
938+
type = string
939+
default = "roles/monitoring.metricWriter"
940+
validation {
941+
condition = can(regex("^(roles/[a-zA-Z0-9_.]+|projects/[a-zA-Z0-9-]+/roles/[a-zA-Z0-9_.]+)$", var.monitoring_metric_writer_role))
942+
error_message = "The monitoring_metric_writer_role must be either a predefined role (roles/*) or a custom role (projects/*/roles/*)."
943+
}
944+
}

‎modules/beta-public-cluster/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ Then perform the following commands on the root folder:
223223
| monitoring\_enable\_observability\_metrics | Whether or not the advanced datapath metrics are enabled. | `bool` | `false` | no |
224224
| monitoring\_enable\_observability\_relay | Whether or not the advanced datapath relay is enabled. | `bool` | `false` | no |
225225
| monitoring\_enabled\_components | List of services to monitor: SYSTEM\_COMPONENTS, APISERVER, SCHEDULER, CONTROLLER\_MANAGER, STORAGE, HPA, POD, DAEMONSET, DEPLOYMENT, STATEFULSET, KUBELET, CADVISOR and DCGM. In beta provider, WORKLOADS is supported on top of those 12 values. (WORKLOADS is deprecated and removed in GKE 1.24.) KUBELET and CADVISOR are only supported in GKE 1.29.3-gke.1093000 and above. Empty list is default GKE configuration. | `list(string)` | `[]` | no |
226+
| monitoring\_metric\_writer\_role | The monitoring metrics writer role to assign to the GKE node service account | `string` | `"roles/monitoring.metricWriter"` | no |
226227
| monitoring\_service | The monitoring service that the cluster should write metrics to. Automatically send metrics from pods in the cluster to the Google Cloud Monitoring API. VM metrics will be collected by Google Compute Engine regardless of this setting Available options include monitoring.googleapis.com, monitoring.googleapis.com/kubernetes (beta) and none | `string` | `"monitoring.googleapis.com/kubernetes"` | no |
227228
| name | The name of the cluster (required) | `string` | n/a | yes |
228229
| network | The VPC network to host the cluster in (required) | `string` | n/a | yes |

‎modules/beta-public-cluster/sa.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ resource "google_project_iam_member" "cluster_service_account_node_service_accou
5656
resource "google_project_iam_member" "cluster_service_account_metric_writer" {
5757
count = var.create_service_account ? 1 : 0
5858
project = google_service_account.cluster_service_account[0].project
59-
role = "roles/monitoring.metricWriter"
59+
role = var.monitoring_metric_writer_role
6060
member = google_service_account.cluster_service_account[0].member
6161
}
6262

‎modules/beta-public-cluster/variables.tf

+10
Original file line numberDiff line numberDiff line change
@@ -932,3 +932,13 @@ variable "fleet_project_grant_service_agent" {
932932
type = bool
933933
default = false
934934
}
935+
936+
variable "monitoring_metric_writer_role" {
937+
description = "The monitoring metrics writer role to assign to the GKE node service account"
938+
type = string
939+
default = "roles/monitoring.metricWriter"
940+
validation {
941+
condition = can(regex("^(roles/[a-zA-Z0-9_.]+|projects/[a-zA-Z0-9-]+/roles/[a-zA-Z0-9_.]+)$", var.monitoring_metric_writer_role))
942+
error_message = "The monitoring_metric_writer_role must be either a predefined role (roles/*) or a custom role (projects/*/roles/*)."
943+
}
944+
}

‎modules/private-cluster-update-variant/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ Then perform the following commands on the root folder:
244244
| monitoring\_enable\_observability\_metrics | Whether or not the advanced datapath metrics are enabled. | `bool` | `false` | no |
245245
| monitoring\_enable\_observability\_relay | Whether or not the advanced datapath relay is enabled. | `bool` | `false` | no |
246246
| monitoring\_enabled\_components | List of services to monitor: SYSTEM\_COMPONENTS, APISERVER, SCHEDULER, CONTROLLER\_MANAGER, STORAGE, HPA, POD, DAEMONSET, DEPLOYMENT, STATEFULSET, KUBELET, CADVISOR and DCGM. In beta provider, WORKLOADS is supported on top of those 12 values. (WORKLOADS is deprecated and removed in GKE 1.24.) KUBELET and CADVISOR are only supported in GKE 1.29.3-gke.1093000 and above. Empty list is default GKE configuration. | `list(string)` | `[]` | no |
247+
| monitoring\_metric\_writer\_role | The monitoring metrics writer role to assign to the GKE node service account | `string` | `"roles/monitoring.metricWriter"` | no |
247248
| monitoring\_service | The monitoring service that the cluster should write metrics to. Automatically send metrics from pods in the cluster to the Google Cloud Monitoring API. VM metrics will be collected by Google Compute Engine regardless of this setting Available options include monitoring.googleapis.com, monitoring.googleapis.com/kubernetes (beta) and none | `string` | `"monitoring.googleapis.com/kubernetes"` | no |
248249
| name | The name of the cluster (required) | `string` | n/a | yes |
249250
| network | The VPC network to host the cluster in (required) | `string` | n/a | yes |

‎modules/private-cluster-update-variant/sa.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ resource "google_project_iam_member" "cluster_service_account_node_service_accou
5656
resource "google_project_iam_member" "cluster_service_account_metric_writer" {
5757
count = var.create_service_account ? 1 : 0
5858
project = google_service_account.cluster_service_account[0].project
59-
role = "roles/monitoring.metricWriter"
59+
role = var.monitoring_metric_writer_role
6060
member = google_service_account.cluster_service_account[0].member
6161
}
6262

‎modules/private-cluster-update-variant/variables.tf

+10
Original file line numberDiff line numberDiff line change
@@ -902,3 +902,13 @@ variable "fleet_project" {
902902
type = string
903903
default = null
904904
}
905+
906+
variable "monitoring_metric_writer_role" {
907+
description = "The monitoring metrics writer role to assign to the GKE node service account"
908+
type = string
909+
default = "roles/monitoring.metricWriter"
910+
validation {
911+
condition = can(regex("^(roles/[a-zA-Z0-9_.]+|projects/[a-zA-Z0-9-]+/roles/[a-zA-Z0-9_.]+)$", var.monitoring_metric_writer_role))
912+
error_message = "The monitoring_metric_writer_role must be either a predefined role (roles/*) or a custom role (projects/*/roles/*)."
913+
}
914+
}

‎modules/private-cluster/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ Then perform the following commands on the root folder:
222222
| monitoring\_enable\_observability\_metrics | Whether or not the advanced datapath metrics are enabled. | `bool` | `false` | no |
223223
| monitoring\_enable\_observability\_relay | Whether or not the advanced datapath relay is enabled. | `bool` | `false` | no |
224224
| monitoring\_enabled\_components | List of services to monitor: SYSTEM\_COMPONENTS, APISERVER, SCHEDULER, CONTROLLER\_MANAGER, STORAGE, HPA, POD, DAEMONSET, DEPLOYMENT, STATEFULSET, KUBELET, CADVISOR and DCGM. In beta provider, WORKLOADS is supported on top of those 12 values. (WORKLOADS is deprecated and removed in GKE 1.24.) KUBELET and CADVISOR are only supported in GKE 1.29.3-gke.1093000 and above. Empty list is default GKE configuration. | `list(string)` | `[]` | no |
225+
| monitoring\_metric\_writer\_role | The monitoring metrics writer role to assign to the GKE node service account | `string` | `"roles/monitoring.metricWriter"` | no |
225226
| monitoring\_service | The monitoring service that the cluster should write metrics to. Automatically send metrics from pods in the cluster to the Google Cloud Monitoring API. VM metrics will be collected by Google Compute Engine regardless of this setting Available options include monitoring.googleapis.com, monitoring.googleapis.com/kubernetes (beta) and none | `string` | `"monitoring.googleapis.com/kubernetes"` | no |
226227
| name | The name of the cluster (required) | `string` | n/a | yes |
227228
| network | The VPC network to host the cluster in (required) | `string` | n/a | yes |

‎modules/private-cluster/sa.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ resource "google_project_iam_member" "cluster_service_account_node_service_accou
5656
resource "google_project_iam_member" "cluster_service_account_metric_writer" {
5757
count = var.create_service_account ? 1 : 0
5858
project = google_service_account.cluster_service_account[0].project
59-
role = "roles/monitoring.metricWriter"
59+
role = var.monitoring_metric_writer_role
6060
member = google_service_account.cluster_service_account[0].member
6161
}
6262

‎modules/private-cluster/variables.tf

+10
Original file line numberDiff line numberDiff line change
@@ -902,3 +902,13 @@ variable "fleet_project" {
902902
type = string
903903
default = null
904904
}
905+
906+
variable "monitoring_metric_writer_role" {
907+
description = "The monitoring metrics writer role to assign to the GKE node service account"
908+
type = string
909+
default = "roles/monitoring.metricWriter"
910+
validation {
911+
condition = can(regex("^(roles/[a-zA-Z0-9_.]+|projects/[a-zA-Z0-9-]+/roles/[a-zA-Z0-9_.]+)$", var.monitoring_metric_writer_role))
912+
error_message = "The monitoring_metric_writer_role must be either a predefined role (roles/*) or a custom role (projects/*/roles/*)."
913+
}
914+
}

‎sa.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ resource "google_project_iam_member" "cluster_service_account_node_service_accou
5656
resource "google_project_iam_member" "cluster_service_account_metric_writer" {
5757
count = var.create_service_account ? 1 : 0
5858
project = google_service_account.cluster_service_account[0].project
59-
role = "roles/monitoring.metricWriter"
59+
role = var.monitoring_metric_writer_role
6060
member = google_service_account.cluster_service_account[0].member
6161
}
6262

‎terraform-google-kubernetes-engine

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 70a28a04e870f2cbc2c6bc3f20ff2bd6ae0b15a9

‎variables.tf

+10
Original file line numberDiff line numberDiff line change
@@ -866,3 +866,13 @@ variable "fleet_project" {
866866
type = string
867867
default = null
868868
}
869+
870+
variable "monitoring_metric_writer_role" {
871+
description = "The monitoring metrics writer role to assign to the GKE node service account"
872+
type = string
873+
default = "roles/monitoring.metricWriter"
874+
validation {
875+
condition = can(regex("^(roles/[a-zA-Z0-9_.]+|projects/[a-zA-Z0-9-]+/roles/[a-zA-Z0-9_.]+)$", var.monitoring_metric_writer_role))
876+
error_message = "The monitoring_metric_writer_role must be either a predefined role (roles/*) or a custom role (projects/*/roles/*)."
877+
}
878+
}

0 commit comments

Comments
 (0)
Please sign in to comment.