From 40c66f9fa98cc20e4b8cca10add572850bef7e92 Mon Sep 17 00:00:00 2001 From: caiotavaresdito Date: Mon, 29 Nov 2021 22:35:07 -0500 Subject: [PATCH 1/6] small var conditional fix --- modules/gcs/outputs.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/gcs/outputs.tf b/modules/gcs/outputs.tf index ce865f2b0..ee21b9d11 100644 --- a/modules/gcs/outputs.tf +++ b/modules/gcs/outputs.tf @@ -25,11 +25,11 @@ output "name" { } output "notification" { description = "GCS Notification self link." - value = local.notification == true ? google_storage_notification.notification[0].self_link : null + value = local.notification ? google_storage_notification.notification[0].self_link : null } output "topic" { description = "Topic ID used by GCS." - value = local.notification == true ? google_pubsub_topic.topic[0].id : null + value = local.notification ? google_pubsub_topic.topic[0].id : null } output "url" { description = "Bucket URL." From 01e100719e7af1045f00cf5dcb3d131a3535a6b0 Mon Sep 17 00:00:00 2001 From: caiotavaresdito Date: Mon, 29 Nov 2021 22:39:44 -0500 Subject: [PATCH 2/6] Added GKE pubsub notifications --- modules/gke-cluster/README.md | 2 ++ modules/gke-cluster/main.tf | 20 ++++++++++++++++++++ modules/gke-cluster/outputs.tf | 5 +++++ modules/gke-cluster/variables.tf | 5 ++++- 4 files changed, 31 insertions(+), 1 deletion(-) diff --git a/modules/gke-cluster/README.md b/modules/gke-cluster/README.md index 9071d8bbd..a58e5bfc5 100644 --- a/modules/gke-cluster/README.md +++ b/modules/gke-cluster/README.md @@ -71,6 +71,7 @@ module "cluster-1" { | location | Cluster zone or region. | string | ✓ | | | name | Cluster name. | string | ✓ | | | network | Name or self link of the VPC used for the cluster. Use the self link for Shared VPC. | string | ✓ | | +| notification_config | GKE Cluster upgrade notifications via PubSub. | bool | ✓ | | | project_id | Cluster project id. | string | ✓ | | | secondary_range_pods | Subnet secondary range name used for pods. | string | ✓ | | | secondary_range_services | Subnet secondary range name used for services. | string | ✓ | | @@ -116,4 +117,5 @@ module "cluster-1" { | location | Cluster location. | | | master_version | Master version. | | | name | Cluster name. | | +| notifications | GKE PubSub notifications topic. | | diff --git a/modules/gke-cluster/main.tf b/modules/gke-cluster/main.tf index 26641338e..faf435e4d 100644 --- a/modules/gke-cluster/main.tf +++ b/modules/gke-cluster/main.tf @@ -277,6 +277,18 @@ resource "google_container_cluster" "cluster" { cluster_dns_domain = config.value.cluster_dns_domain } } + + dynamic "notification_config" { + + for_each = var.notification_config != null ? [""] : [] + content { + pubsub { + enabled = var.notification_config + topic = var.notification_config ? google_pubsub_topic.notifications[0].id : null + } + } + } + } resource "google_compute_network_peering_routes_config" "gke_master" { @@ -287,3 +299,11 @@ resource "google_compute_network_peering_routes_config" "gke_master" { import_custom_routes = var.peering_config.import_routes export_custom_routes = var.peering_config.export_routes } + +resource "google_pubsub_topic" "notifications" { + count = var.notification_config ? 1 : 0 + name = "gke-pubsub-notifications" + labels = { + content = "gke-notifications" + } +} \ No newline at end of file diff --git a/modules/gke-cluster/outputs.tf b/modules/gke-cluster/outputs.tf index aab61c0d1..2ee357e6c 100644 --- a/modules/gke-cluster/outputs.tf +++ b/modules/gke-cluster/outputs.tf @@ -45,3 +45,8 @@ output "name" { description = "Cluster name." value = google_container_cluster.cluster.name } + +output "notifications" { + description = "GKE PubSub notifications topic." + value = google_pubsub_topic.notifications.id +} diff --git a/modules/gke-cluster/variables.tf b/modules/gke-cluster/variables.tf index 5bcc316f5..a303907a2 100644 --- a/modules/gke-cluster/variables.tf +++ b/modules/gke-cluster/variables.tf @@ -236,7 +236,10 @@ variable "node_locations" { type = list(string) default = [] } - +variable "notification_config" { + description = "GKE Cluster upgrade notifications via PubSub." + type = bool +} variable "peering_config" { description = "Configure peering with the master VPC for private clusters." type = object({ From da296c8bfeb3e7207286c1146c0fa237a512e8c5 Mon Sep 17 00:00:00 2001 From: caiotavaresdito Date: Mon, 29 Nov 2021 22:49:01 -0500 Subject: [PATCH 3/6] Default creation false --- modules/gke-cluster/variables.tf | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/gke-cluster/variables.tf b/modules/gke-cluster/variables.tf index a303907a2..8b38a8aec 100644 --- a/modules/gke-cluster/variables.tf +++ b/modules/gke-cluster/variables.tf @@ -239,6 +239,7 @@ variable "node_locations" { variable "notification_config" { description = "GKE Cluster upgrade notifications via PubSub." type = bool + default = false } variable "peering_config" { description = "Configure peering with the master VPC for private clusters." From 5a9183d90813cf5291f0be2b607d513b49bef932 Mon Sep 17 00:00:00 2001 From: caiotavaresdito Date: Mon, 29 Nov 2021 23:09:36 -0500 Subject: [PATCH 4/6] Updated variable default value --- modules/gke-cluster/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/gke-cluster/README.md b/modules/gke-cluster/README.md index a58e5bfc5..dc6d18d71 100644 --- a/modules/gke-cluster/README.md +++ b/modules/gke-cluster/README.md @@ -71,7 +71,6 @@ module "cluster-1" { | location | Cluster zone or region. | string | ✓ | | | name | Cluster name. | string | ✓ | | | network | Name or self link of the VPC used for the cluster. Use the self link for Shared VPC. | string | ✓ | | -| notification_config | GKE Cluster upgrade notifications via PubSub. | bool | ✓ | | | project_id | Cluster project id. | string | ✓ | | | secondary_range_pods | Subnet secondary range name used for pods. | string | ✓ | | | secondary_range_services | Subnet secondary range name used for services. | string | ✓ | | @@ -99,6 +98,7 @@ module "cluster-1" { | *monitoring_config* | Monitoring configuration (enabled components). | list(string) | | null | | *monitoring_service* | Monitoring service (disable with an empty string). | string | | monitoring.googleapis.com/kubernetes | | *node_locations* | Zones in which the cluster's nodes are located. | list(string) | | [] | +| *notification_config* | GKE Cluster upgrade notifications via PubSub. | bool | | false | | *peering_config* | Configure peering with the master VPC for private clusters. | object({...}) | | null | | *pod_security_policy* | Enable the PodSecurityPolicy feature. | bool | | null | | *private_cluster_config* | Enable and configure private cluster, private nodes must be true if used. | object({...}) | | null | From fd4383540a9ce38a4a952fa77b4a4b9a4a5f7e62 Mon Sep 17 00:00:00 2001 From: caiotavaresdito Date: Tue, 30 Nov 2021 07:50:53 -0500 Subject: [PATCH 5/6] removed extra lines --- modules/gke-cluster/main.tf | 2 -- modules/gke-cluster/variables.tf | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/gke-cluster/main.tf b/modules/gke-cluster/main.tf index faf435e4d..9de06be8f 100644 --- a/modules/gke-cluster/main.tf +++ b/modules/gke-cluster/main.tf @@ -279,7 +279,6 @@ resource "google_container_cluster" "cluster" { } dynamic "notification_config" { - for_each = var.notification_config != null ? [""] : [] content { pubsub { @@ -288,7 +287,6 @@ resource "google_container_cluster" "cluster" { } } } - } resource "google_compute_network_peering_routes_config" "gke_master" { diff --git a/modules/gke-cluster/variables.tf b/modules/gke-cluster/variables.tf index 8b38a8aec..4c2bf2ecd 100644 --- a/modules/gke-cluster/variables.tf +++ b/modules/gke-cluster/variables.tf @@ -236,11 +236,13 @@ variable "node_locations" { type = list(string) default = [] } + variable "notification_config" { description = "GKE Cluster upgrade notifications via PubSub." type = bool default = false } + variable "peering_config" { description = "Configure peering with the master VPC for private clusters." type = object({ From c9870b44f1f87bc0dbeae60bef503901bec21ee1 Mon Sep 17 00:00:00 2001 From: caiotavaresdito Date: Tue, 30 Nov 2021 07:58:45 -0500 Subject: [PATCH 6/6] defaulted to false and conditional output --- modules/gke-cluster/main.tf | 2 +- modules/gke-cluster/outputs.tf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/gke-cluster/main.tf b/modules/gke-cluster/main.tf index 9de06be8f..572e35c11 100644 --- a/modules/gke-cluster/main.tf +++ b/modules/gke-cluster/main.tf @@ -279,7 +279,7 @@ resource "google_container_cluster" "cluster" { } dynamic "notification_config" { - for_each = var.notification_config != null ? [""] : [] + for_each = var.notification_config ? [""] : [] content { pubsub { enabled = var.notification_config diff --git a/modules/gke-cluster/outputs.tf b/modules/gke-cluster/outputs.tf index 2ee357e6c..df0b40c18 100644 --- a/modules/gke-cluster/outputs.tf +++ b/modules/gke-cluster/outputs.tf @@ -48,5 +48,5 @@ output "name" { output "notifications" { description = "GKE PubSub notifications topic." - value = google_pubsub_topic.notifications.id + value = var.notification_config ? google_pubsub_topic.notifications[0].id : null }