Skip to content

Commit aa461f9

Browse files
committed
add new functionality for monitoring
1 parent a0a2ac0 commit aa461f9

2 files changed

Lines changed: 127 additions & 103 deletions

File tree

main.tf

Lines changed: 111 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ provider "google-beta" {
2424

2525
locals {
2626
# Postgres DB Name
27-
gitlab_db_name = var.postgresql_db_random_suffix ? "${var.gitlab_db_name}-${random_id.suffix[0].hex}" : var.gitlab_db_name
27+
gitlab_db_name = var.postgresql_db_random_suffix ? "${var.gitlab_db_name}-${random_id.suffix[0].hex}" : var.gitlab_db_name
2828
# Gitlab Bucket Names
2929
gitlab_backups_bucket_name = var.gcs_bucket_random_suffix ? "${var.project_id}-gitlab-backups-${random_id.bucket_suffix[0].hex}" : "${var.project_id}-gitlab-backups"
3030
gitlab_tmp_backups_bucket_name = var.gcs_bucket_random_suffix ? "${var.project_id}-gitlab-tmp-backups-${random_id.bucket_suffix[0].hex}" : "${var.project_id}-gitlab-tmp-backups"
@@ -41,12 +41,12 @@ locals {
4141
}
4242

4343
resource "random_id" "suffix" {
44-
count = var.postgresql_db_random_suffix ? 2 : 1
44+
count = var.postgresql_db_random_suffix ? 2 : 1
4545
byte_length = 4
4646
}
4747

4848
resource "random_id" "bucket_suffix" {
49-
count = var.gcs_bucket_random_suffix ? 1 : 0
49+
count = var.gcs_bucket_random_suffix ? 1 : 0
5050
byte_length = 4
5151
}
5252

@@ -137,15 +137,15 @@ resource "google_compute_address" "gitlab" {
137137
}
138138

139139
module "cloud_nat" {
140-
source = "terraform-google-modules/cloud-nat/google"
141-
version = "~> 2.2.0"
142-
project_id = var.project_id
143-
region = var.region
144-
router = format("%s-router", var.project_id)
145-
name = "${var.project_id}-cloud-nat-${random_id.suffix[1].hex}"
146-
network = google_compute_network.gitlab.self_link
147-
create_router = true
148-
min_ports_per_vm = "2048"
140+
source = "terraform-google-modules/cloud-nat/google"
141+
version = "~> 2.2.0"
142+
project_id = var.project_id
143+
region = var.region
144+
router = format("%s-router", var.project_id)
145+
name = "${var.project_id}-cloud-nat-${random_id.suffix[1].hex}"
146+
network = google_compute_network.gitlab.self_link
147+
create_router = true
148+
min_ports_per_vm = "2048"
149149
}
150150

151151
resource "google_compute_firewall" "admission_webhook" {
@@ -180,18 +180,18 @@ resource "google_service_networking_connection" "private_vpc_connection" {
180180
}
181181

182182
resource "google_sql_database_instance" "gitlab_db" {
183-
depends_on = [google_service_networking_connection.private_vpc_connection]
184-
name = local.gitlab_db_name
185-
region = var.region
186-
database_version = var.postgresql_version
187-
deletion_protection = var.postgresql_del_protection
183+
depends_on = [google_service_networking_connection.private_vpc_connection]
184+
name = local.gitlab_db_name
185+
region = var.region
186+
database_version = var.postgresql_version
187+
deletion_protection = var.postgresql_del_protection
188188

189189
settings {
190-
tier = var.postgresql_tier
191-
availability_type = var.postgresql_availability_type
192-
disk_size = var.postgresql_disk_size
193-
disk_type = var.postgresql_disk_type
194-
disk_autoresize = true
190+
tier = var.postgresql_tier
191+
availability_type = var.postgresql_availability_type
192+
disk_size = var.postgresql_disk_size
193+
disk_type = var.postgresql_disk_type
194+
disk_autoresize = true
195195

196196
ip_configuration {
197197
ipv4_enabled = "false"
@@ -203,9 +203,9 @@ resource "google_sql_database_instance" "gitlab_db" {
203203
enabled = var.postgresql_enable_backup
204204
start_time = var.postgresql_backup_start_time
205205
point_in_time_recovery_enabled = true
206-
backup_retention_settings {
207-
retained_backups = var. postgresql_backup_retained_count
208-
}
206+
backup_retention_settings {
207+
retained_backups = var.postgresql_backup_retained_count
208+
}
209209
}
210210

211211
maintenance_window {
@@ -229,8 +229,8 @@ resource "google_sql_user" "gitlab" {
229229
}
230230

231231
resource "google_sql_database" "gitlabhq_production" {
232-
name = "gitlabhq_production"
233-
instance = google_sql_database_instance.gitlab_db.name
232+
name = "gitlabhq_production"
233+
instance = google_sql_database_instance.gitlab_db.name
234234
}
235235

236236
# Redis
@@ -339,35 +339,35 @@ module "gke" {
339339
# Create an implicit dependency on service activation
340340
project_id = module.project_services.project_id
341341

342-
name = "gitlab"
343-
region = var.region
344-
regional = true
345-
kubernetes_version = var.gke_version
346-
347-
network = google_compute_network.gitlab.name
348-
subnetwork = google_compute_subnetwork.subnetwork.name
349-
ip_range_pods = "gitlab-cluster-pod-cidr"
350-
ip_range_services = "gitlab-cluster-service-cidr"
351-
352-
enable_private_endpoint = false
353-
enable_private_nodes = true
354-
release_channel = "STABLE"
355-
maintenance_start_time = "03:00"
356-
network_policy = false
357-
enable_shielded_nodes = true
358-
dns_cache = true
359-
360-
remove_default_node_pool = true
361-
342+
name = "gitlab"
343+
region = var.region
344+
regional = true
345+
kubernetes_version = var.gke_version
346+
347+
network = google_compute_network.gitlab.name
348+
subnetwork = google_compute_subnetwork.subnetwork.name
349+
ip_range_pods = "gitlab-cluster-pod-cidr"
350+
ip_range_services = "gitlab-cluster-service-cidr"
351+
352+
enable_private_endpoint = false
353+
enable_private_nodes = true
354+
release_channel = "STABLE"
355+
maintenance_start_time = "03:00"
356+
network_policy = false
357+
enable_shielded_nodes = true
358+
dns_cache = true
359+
360+
remove_default_node_pool = true
361+
362362
# Kube-proxy - eBPF setting
363-
datapath_provider = var.gke_datapath
363+
datapath_provider = var.gke_datapath
364364
# Google Group for RBAC
365-
authenticator_security_group = var.gke_google_group_rbac_mail
365+
authenticator_security_group = var.gke_google_group_rbac_mail
366366
# Backup for GKE
367-
gke_backup_agent_config = var.gke_enable_backup_agent
367+
gke_backup_agent_config = var.gke_enable_backup_agent
368368
# Istio
369-
istio = var.gke_enable_istio_addon
370-
istio_auth = var.gke_istio_auth
369+
istio = var.gke_enable_istio_addon
370+
istio_auth = var.gke_istio_auth
371371

372372
node_pools = [
373373
{
@@ -385,10 +385,10 @@ module "gke" {
385385
cloudrun = var.gke_enable_cloudrun
386386
enable_pod_security_policy = false
387387
preemptible = false
388-
autoscaling = true
389-
388+
autoscaling = true
389+
390390
#Image Streaming
391-
enable_gcfs = var.gke_enable_image_stream
391+
enable_gcfs = var.gke_enable_image_stream
392392
},
393393
]
394394

@@ -410,21 +410,21 @@ resource "kubernetes_storage_class" "storage_class" {
410410
}
411411
storage_provisioner = "kubernetes.io/gce-pd"
412412
parameters = {
413-
type = var.gke_storage_class
413+
type = var.gke_storage_class
414414
replication-type = var.gke_disk_replication
415415
}
416416
depends_on = [time_sleep.sleep_for_cluster_fix_helm_6361]
417417
}
418418

419419
# Secret for Postgres DB Pass
420420
module "gitlab_db_pass" {
421-
source = "./modules/secret_manager"
422-
project = var.project_id
423-
region = var.region
424-
secret_id = var.gcp_existing_db_secret_name
425-
k8s_namespace = var.gitlab_namespace
426-
k8s_secret_name = "gitlab-postgres-secret"
427-
k8s_secret_key = "password"
421+
source = "./modules/secret_manager"
422+
project = var.project_id
423+
region = var.region
424+
secret_id = var.gcp_existing_db_secret_name
425+
k8s_namespace = var.gitlab_namespace
426+
k8s_secret_name = "gitlab-postgres-secret"
427+
k8s_secret_key = "password"
428428

429429
depends_on = [kubernetes_namespace.gitlab_namespace]
430430
}
@@ -490,39 +490,39 @@ resource "kubernetes_secret" "postgresql_mtls_secret" {
490490
}
491491

492492
data = {
493-
cert = google_sql_ssl_cert.postgres_client_cert.cert
494-
private_key = google_sql_ssl_cert.postgres_client_cert.private_key
495-
server_ca_cert = google_sql_ssl_cert.postgres_client_cert.server_ca_cert
493+
cert = google_sql_ssl_cert.postgres_client_cert.cert
494+
private_key = google_sql_ssl_cert.postgres_client_cert.private_key
495+
server_ca_cert = google_sql_ssl_cert.postgres_client_cert.server_ca_cert
496496
}
497497
depends_on = [kubernetes_namespace.gitlab_namespace]
498498
}
499499

500500
#Secret for SMTP Pass
501501
module "gitlab_smtp_pass" {
502-
source = "./modules/secret_manager"
503-
project = var.project_id
504-
region = var.region
505-
secret_id = var.gcp_existing_smtp_secret_name
506-
k8s_namespace = var.gitlab_namespace
507-
k8s_secret_name = "gitlab-smtp-secret"
508-
k8s_secret_key = "password"
509-
510-
count = var.gitlab_enable_smtp ? 1 : 0
502+
source = "./modules/secret_manager"
503+
project = var.project_id
504+
region = var.region
505+
secret_id = var.gcp_existing_smtp_secret_name
506+
k8s_namespace = var.gitlab_namespace
507+
k8s_secret_name = "gitlab-smtp-secret"
508+
k8s_secret_key = "password"
509+
510+
count = var.gitlab_enable_smtp ? 1 : 0
511511
depends_on = [kubernetes_namespace.gitlab_namespace]
512512
}
513513

514514
#Secret for Omniauth Pass
515515
module "gitlab_omniauth_pass" {
516-
source = "./modules/secret_manager"
517-
project = var.project_id
518-
region = var.region
519-
secret_id = var.gcp_existing_omniauth_secret_name
520-
k8s_namespace = var.gitlab_namespace
521-
k8s_secret_name = "gitlab-omniauth-secret"
522-
k8s_secret_key = "provider"
523-
524-
count = var.gitlab_enable_omniauth ? 1 : 0
525-
depends_on = [kubernetes_namespace.gitlab_namespace]
516+
source = "./modules/secret_manager"
517+
project = var.project_id
518+
region = var.region
519+
secret_id = var.gcp_existing_omniauth_secret_name
520+
k8s_namespace = var.gitlab_namespace
521+
k8s_secret_name = "gitlab-omniauth-secret"
522+
k8s_secret_key = "provider"
523+
524+
count = var.gitlab_enable_omniauth ? 1 : 0
525+
depends_on = [kubernetes_namespace.gitlab_namespace]
526526
}
527527

528528
data "google_compute_address" "gitlab" {
@@ -534,9 +534,9 @@ data "google_compute_address" "gitlab" {
534534
}
535535

536536
locals {
537-
gitlab_address = var.gitlab_address_name == "" ? google_compute_address.gitlab[0].address : data.google_compute_address.gitlab[0].address
538-
domain = var.domain != "" ? var.domain : "${local.gitlab_address}.xip.io"
539-
gitlab_smtp_user = var.gitlab_enable_smtp != false ? var.gitlab_smtp_user : ""
537+
gitlab_address = var.gitlab_address_name == "" ? google_compute_address.gitlab[0].address : data.google_compute_address.gitlab[0].address
538+
domain = var.domain != "" ? var.domain : "${local.gitlab_address}.xip.io"
539+
gitlab_smtp_user = var.gitlab_enable_smtp != false ? var.gitlab_smtp_user : ""
540540
}
541541

542542
data "template_file" "helm_values" {
@@ -559,9 +559,9 @@ data "template_file" "helm_values" {
559559
ENABLE_CRON_BACKUP = var.gitlab_enable_cron_backup
560560
SCHEDULE_CRON_BACKUP = var.gitlab_schedule_cron_backup
561561
GITALY_PV_SIZE = var.gitlab_gitaly_disk_size
562-
PV_STORAGE_CLASS = var.gke_storage_class
562+
PV_STORAGE_CLASS = var.gke_storage_class
563563
ENABLE_SMTP = var.gitlab_enable_smtp
564-
SMTP_USER = local.gitlab_smtp_user
564+
SMTP_USER = local.gitlab_smtp_user
565565
BACKUP_EXTRA = var.gitlab_backup_extra_args
566566
TIMEZONE = var.gitlab_time_zone
567567
ENABLE_OMNIAUTH = var.gitlab_enable_omniauth
@@ -573,17 +573,17 @@ data "template_file" "helm_values" {
573573
RESTORE_PV_SC = var.gke_sc_gitlab_restore_disk
574574

575575
#Bucket Names
576-
LFS_BCKT = local.git_lfs_bucket_name
577-
ARTIFACTS_BCKT = local.gitlab_artifacts_bucket_name
578-
UPLOADS_BCKT = local.gitlab_uploads_bucket_name
579-
PACKAGES_BCKT = local.gitlab_packages_bucket_name
580-
EXT_DIFF_BCKT = local.gitlab_external_diffs_bucket_name
581-
TERRAFORM_BCKT = local.gitlab_terraform_state_bucket_name
582-
DEP_PROXY_BCKT = local.gitlab_dependency_proxy_bucket_name
583-
BACKUP_BCKT = local.gitlab_backups_bucket_name
584-
BACKUP_TMP_BCKT = local.gitlab_tmp_backups_bucket_name
585-
REGISTRY_BCKT = local.gitlab_registry_bucket_name
586-
RUNNER_CACHE_BCKT = local.gitlab_runner_cache_bucket_name
576+
LFS_BCKT = local.git_lfs_bucket_name
577+
ARTIFACTS_BCKT = local.gitlab_artifacts_bucket_name
578+
UPLOADS_BCKT = local.gitlab_uploads_bucket_name
579+
PACKAGES_BCKT = local.gitlab_packages_bucket_name
580+
EXT_DIFF_BCKT = local.gitlab_external_diffs_bucket_name
581+
TERRAFORM_BCKT = local.gitlab_terraform_state_bucket_name
582+
DEP_PROXY_BCKT = local.gitlab_dependency_proxy_bucket_name
583+
BACKUP_BCKT = local.gitlab_backups_bucket_name
584+
BACKUP_TMP_BCKT = local.gitlab_tmp_backups_bucket_name
585+
REGISTRY_BCKT = local.gitlab_registry_bucket_name
586+
RUNNER_CACHE_BCKT = local.gitlab_runner_cache_bucket_name
587587

588588
# HPA settings for cost/performance optimization
589589
HPA_MIN_REPLICAS_REGISTRY = var.gitlab_hpa_min_replicas_registry
@@ -630,3 +630,13 @@ resource "helm_release" "gitlab" {
630630
module.gitlab_db_pass,
631631
]
632632
}
633+
634+
module "monitoring" {
635+
source = "sparkfabrik/gcp-http-monitoring/sparkfabrik"
636+
version = "~> 0.4.0"
637+
count = var.notification_channels != "" ? 1 : 0
638+
gcp_project = var.project_id
639+
uptime_monitoring_host = var.domain
640+
uptime_monitoring_path = var.uptime_monitoring_path
641+
alert_notification_channels = var.notification_channels
642+
}

variables.tf

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ variable "gitlab_namespace" {
360360
variable "gitlab_backup_extra_args" {
361361
type = string
362362
description = "Add a string of extra arguments for the gitlab backup-utility."
363-
default = ""
363+
default = ""
364364
}
365365

366366
variable "gitlab_enable_registry" {
@@ -477,4 +477,18 @@ variable "gitlab_hpa_max_replicas_webservice" {
477477
description = "Set the maximum hpa pod replicas for the Gitlab webservice."
478478
default = 10
479479
}
480-
480+
481+
######################
482+
# MONITORING SECTION #
483+
######################
484+
485+
variable "uptime_monitoring_path" {
486+
type = string
487+
description = "The path to the page to run the check against."
488+
default = "/-/liveness"
489+
}
490+
491+
variable "notification_channels" {
492+
type = list(string)
493+
description = "Identifies the notification channels to which notifications should be sent when incidents are opened or closed. The syntax of the entries in this field is projects/[PROJECT_ID]/notificationChannels/[CHANNEL_ID]"
494+
}

0 commit comments

Comments
 (0)