Added GKE pubsub notifications

This commit is contained in:
caiotavaresdito 2021-11-29 22:39:44 -05:00
parent 40c66f9fa9
commit 01e100719e
4 changed files with 31 additions and 1 deletions

View File

@ -71,6 +71,7 @@ module "cluster-1" {
| location | Cluster zone or region. | <code title="">string</code> | ✓ | |
| name | Cluster name. | <code title="">string</code> | ✓ | |
| network | Name or self link of the VPC used for the cluster. Use the self link for Shared VPC. | <code title="">string</code> | ✓ | |
| notification_config | GKE Cluster upgrade notifications via PubSub. | <code title="">bool</code> | ✓ | |
| project_id | Cluster project id. | <code title="">string</code> | ✓ | |
| secondary_range_pods | Subnet secondary range name used for pods. | <code title="">string</code> | ✓ | |
| secondary_range_services | Subnet secondary range name used for services. | <code title="">string</code> | ✓ | |
@ -116,4 +117,5 @@ module "cluster-1" {
| location | Cluster location. | |
| master_version | Master version. | |
| name | Cluster name. | |
| notifications | GKE PubSub notifications topic. | |
<!-- END TFDOC -->

View File

@ -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"
}
}

View File

@ -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
}

View File

@ -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({