main.tf 35.6 KB
Newer Older
John Jarvis's avatar
John Jarvis committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
## State storage
terraform {
  backend "s3" {}
}

## AWS
provider "aws" {
  region = "us-east-1"
}

variable "gitlab_com_zone_id" {}
variable "gitlab_net_zone_id" {}

## Google

provider "google" {
17
  version = "~> 2.7.0"
John Jarvis's avatar
John Jarvis committed
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
  project = "${var.project}"
  region  = "${var.region}"
}

##################################
#
#  Network
#
#################################

module "network" {
  source           = "git::ssh://[email protected]/gitlab-com/gl-infra/terraform-modules/google/vpc.git?ref=v1.0.0"
  project          = "${var.project}"
  environment      = "${var.environment}"
  internal_subnets = "${var.internal_subnets}"
}

##################################
#
#  Network Peering
#
#################################

resource "google_compute_network_peering" "peering" {
  count        = "${length(var.peer_networks["names"])}"
  name         = "peering-${element(var.peer_networks["names"], count.index)}"
  network      = "${var.network_env}"
  peer_network = "${element(var.peer_networks["links"], count.index)}"
}

##################################
#
#  Monitoring
#
#  Uses the monitoring module, this
#  creates a single instance behind
#  a load balancer with identity aware
#  proxy enabled.
#
##################################

resource "google_compute_subnetwork" "monitoring" {
  ip_cidr_range            = "${var.subnetworks["monitoring"]}"
  name                     = "${format("monitoring-%v", var.environment)}"
  network                  = "${module.network.self_link}"
  private_ip_google_access = true
  project                  = "${var.project}"
  region                   = "${var.region}"
}

#######################
#
# load balancer for all hosts in this section
#
#######################

module "monitoring-lb" {
  cert_link          = "${var.monitoring_cert_link}"
  environment        = "${var.environment}"
  gitlab_net_zone_id = "${var.gitlab_net_zone_id}"
  hosts              = ["${var.monitoring_hosts["names"]}"]
  name               = "monitoring-lb"
  project            = "${var.project}"
  region             = "${var.region}"
  service_ports      = ["${var.monitoring_hosts["ports"]}"]
  source             = "git::ssh://[email protected]/gitlab-com/gl-infra/terraform-modules/google/monitoring-lb.git?ref=v1.0.0"
  subnetwork_name    = "${google_compute_subnetwork.monitoring.name}"
  targets            = ["${var.monitoring_hosts["names"]}"]
  url_map            = "${google_compute_url_map.monitoring-lb.self_link}"
}

#######################
module "prometheus" {
  bootstrap_version     = 6
  chef_provision        = "${var.chef_provision}"
  chef_run_list         = "\"role[${var.environment}-infra-prometheus]\""
Ahmad Sherif's avatar
Ahmad Sherif committed
94
  data_disk_size        = 50
John Jarvis's avatar
John Jarvis committed
95
  data_disk_type        = "pd-ssd"
John Jarvis's avatar
John Jarvis committed
96 97
  dns_zone_name         = "${var.dns_zone_name}"
  environment           = "${var.environment}"
98 99
  fw_whitelist_subnets  = "${concat(var.monitoring_whitelist_prometheus["subnets"], var.other_monitoring_subnets)}"
  fw_whitelist_ports    = "${var.monitoring_whitelist_prometheus["ports"]}"
John Jarvis's avatar
John Jarvis committed
100 101 102 103 104 105 106 107 108 109 110 111
  machine_type          = "${var.machine_types["monitoring"]}"
  name                  = "prometheus"
  node_count            = "${var.node_count["prometheus"]}"
  oauth2_client_id      = "${var.oauth2_client_id_monitoring}"
  oauth2_client_secret  = "${var.oauth2_client_secret_monitoring}"
  persistent_disk_path  = "/opt/prometheus"
  project               = "${var.project}"
  public_ports          = ["22"]
  region                = "${var.region}"
  service_account_email = "${var.service_account_email}"
  service_path          = "/graph"
  service_port          = "${element(var.monitoring_hosts["ports"], index(var.monitoring_hosts["names"], "prometheus"))}"
112
  source                = "git::ssh://[email protected]/gitlab-com/gl-infra/terraform-modules/google/monitoring-with-count.git?ref=v1.0.5"
John Jarvis's avatar
John Jarvis committed
113 114 115 116
  subnetwork_name       = "${google_compute_subnetwork.monitoring.name}"
  tier                  = "inf"
  use_external_ip       = true
  use_new_node_name     = true
117
  vpc                   = "${module.network.self_link}"
John Jarvis's avatar
John Jarvis committed
118 119 120 121 122 123
}

module "prometheus-app" {
  bootstrap_version     = 6
  chef_provision        = "${var.chef_provision}"
  chef_run_list         = "\"role[${var.environment}-infra-prometheus-app]\""
Ahmad Sherif's avatar
Ahmad Sherif committed
124
  data_disk_size        = 50
John Jarvis's avatar
John Jarvis committed
125
  data_disk_type        = "pd-ssd"
John Jarvis's avatar
John Jarvis committed
126 127
  dns_zone_name         = "${var.dns_zone_name}"
  environment           = "${var.environment}"
128 129
  fw_whitelist_subnets  = "${concat(var.monitoring_whitelist_prometheus["subnets"], var.other_monitoring_subnets)}"
  fw_whitelist_ports    = "${var.monitoring_whitelist_prometheus["ports"]}"
John Jarvis's avatar
John Jarvis committed
130 131 132 133 134 135 136 137 138 139 140
  machine_type          = "${var.machine_types["monitoring"]}"
  name                  = "prometheus-app"
  node_count            = "${var.node_count["prometheus-app"]}"
  oauth2_client_id      = "${var.oauth2_client_id_monitoring}"
  oauth2_client_secret  = "${var.oauth2_client_secret_monitoring}"
  persistent_disk_path  = "/opt/prometheus"
  project               = "${var.project}"
  region                = "${var.region}"
  service_account_email = "${var.service_account_email}"
  service_path          = "/graph"
  service_port          = "${element(var.monitoring_hosts["ports"], index(var.monitoring_hosts["names"], "prometheus-app"))}"
141
  source                = "git::ssh://[email protected]/gitlab-com/gl-infra/terraform-modules/google/monitoring-with-count.git?ref=v1.0.5"
John Jarvis's avatar
John Jarvis committed
142 143 144 145
  subnetwork_name       = "${google_compute_subnetwork.monitoring.name}"
  tier                  = "inf"
  use_external_ip       = true
  use_new_node_name     = true
146
  vpc                   = "${module.network.self_link}"
John Jarvis's avatar
John Jarvis committed
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
}

module "sd-exporter" {
  additional_scopes         = ["https://www.googleapis.com/auth/monitoring"]
  allow_stopping_for_update = true
  bootstrap_version         = 6
  chef_provision            = "${var.chef_provision}"
  chef_run_list             = "\"role[${var.environment}-infra-sd-exporter]\""
  create_backend_service    = false
  dns_zone_name             = "${var.dns_zone_name}"
  environment               = "${var.environment}"
  machine_type              = "${var.machine_types["sd-exporter"]}"
  name                      = "sd-exporter"
  node_count                = "${var.node_count["sd-exporter"]}"
  project                   = "${var.project}"
  public_ports              = "${var.public_ports["sd-exporter"]}"
  region                    = "${var.region}"
  service_account_email     = "${var.service_account_email}"
165
  source                    = "git::ssh://[email protected]/gitlab-com/gl-infra/terraform-modules/google/generic-sv-with-group.git?ref=v1.0.4"
John Jarvis's avatar
John Jarvis committed
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
  subnetwork_name           = "${google_compute_subnetwork.monitoring.name}"
  tier                      = "inf"
  use_new_node_name         = true
  vpc                       = "${module.network.self_link}"
}

###############################################
#
# Load balancer and VM for the pre bastion
#
###############################################

module "gcp-tcp-lb-bastion" {
  environment            = "${var.environment}"
  forwarding_port_ranges = "${var.tcp_lbs_bastion["forwarding_port_ranges"]}"
  fqdns                  = "${var.lb_fqdns_bastion}"
  gitlab_zone_id         = "${var.gitlab_com_zone_id}"
  health_check_ports     = "${var.tcp_lbs_bastion["health_check_ports"]}"
  instances              = ["${module.bastion.instances_self_link}"]
  lb_count               = "${length(var.tcp_lbs_bastion["names"])}"
  name                   = "gcp-tcp-lb-bastion"
  names                  = "${var.tcp_lbs_bastion["names"]}"
  project                = "${var.project}"
  region                 = "${var.region}"
  session_affinity       = "CLIENT_IP"
  source                 = "git::ssh://[email protected]/gitlab-com/gl-infra/terraform-modules/google/tcp-lb.git?ref=remove-lifecycle"
  targets                = ["bastion"]
}

module "bastion" {
  bootstrap_version     = 6
  chef_provision        = "${var.chef_provision}"
  chef_run_list         = "\"role[${var.environment}-base-bastion]\""
  dns_zone_name         = "${var.dns_zone_name}"
  environment           = "${var.environment}"
  health_check          = "tcp"
  ip_cidr_range         = "${var.subnetworks["bastion"]}"
  machine_type          = "${var.machine_types["bastion"]}"
  name                  = "bastion"
  node_count            = "${var.node_count["bastion"]}"
  project               = "${var.project}"
  public_ports          = "${var.public_ports["bastion"]}"
  region                = "${var.region}"
  service_account_email = "${var.service_account_email}"
  service_port          = 22
211
  source                = "git::ssh://[email protected]/gitlab-com/gl-infra/terraform-modules/google/generic-sv-with-group.git?ref=v1.0.4"
John Jarvis's avatar
John Jarvis committed
212 213 214
  tier                  = "inf"
  use_new_node_name     = true
  vpc                   = "${module.network.self_link}"
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
}

##################################
#
#  Consul
#
##################################

module "consul" {
  bootstrap_version     = "${var.bootstrap_script_version}"
  chef_provision        = "${var.chef_provision}"
  chef_run_list         = "\"role[${var.environment}-infra-consul]\""
  dns_zone_name         = "${var.dns_zone_name}"
  environment           = "${var.environment}"
  ip_cidr_range         = "${var.subnetworks["consul"]}"
  machine_type          = "${var.machine_types["consul"]}"
  name                  = "consul"
  node_count            = "${var.node_count["consul"]}"
  project               = "${var.project}"
  public_ports          = "${var.public_ports["consul"]}"
  region                = "${var.region}"
  service_account_email = "${var.service_account_email}"
  service_port          = 8300
238
  source                = "git::ssh://[email protected]/gitlab-com/gl-infra/terraform-modules/google/generic-sv-with-group.git?ref=v1.0.4"
239 240 241
  tier                  = "inf"
  use_new_node_name     = true
  vpc                   = "${module.network.self_link}"
John Jarvis's avatar
John Jarvis committed
242 243 244 245 246 247 248 249 250 251 252 253 254
}

##################################
#
#  Google storage buckets
#
##################################

module "storage" {
  environment                       = "${var.environment}"
  service_account_email             = "${var.service_account_email}"
  gcs_service_account_email         = "${var.gcs_service_account_email}"
  gcs_storage_analytics_group_email = "${var.gcs_storage_analytics_group_email}"
255
  source                            = "git::ssh://[email protected]/gitlab-com/gl-infra/terraform-modules/google/storage-buckets.git?ref=v1.2.0"
John Jarvis's avatar
John Jarvis committed
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
}

##################################
#
#  GKE Cluster for runners
#
##################################

# After provisioning you will need to configure
# the cluster for gitlab-runner. Instructions
# for this are in https://gitlab.com/gitlab-com/runbooks/tree/master/gke-runner

module "gke-runner" {
  environment           = "${var.environment}"
  name                  = "gke-runner"
  vpc                   = "${module.network.self_link}"
John Skarbek's avatar
John Skarbek committed
272
  source                = "git::ssh://[email protected]/gitlab-com/gl-infra/terraform-modules/google/gke.git?ref=v2.0.0"
John Jarvis's avatar
John Jarvis committed
273 274 275 276 277 278
  initial_node_count    = 1
  ip_cidr_range         = "${var.subnetworks["gke-runner"]}"
  dns_zone_name         = "${var.dns_zone_name}"
  machine_type          = "${var.machine_types["gke-runner"]}"
  project               = "${var.project}"
  region                = "${var.region}"
279 280 281 282 283 284
  pod_ip_cidr_range     = "${var.subnetworks["gke-runner-pod-cidr"]}"
  service_ip_cidr_range = "${var.subnetworks["gke-runner-service-cidr"]}"
}

##################################
#
285
#  GKE Cluster for pre.gitlab.com GitLab services
286 287 288
#
##################################

289 290 291 292 293
# IP address for the GitLab application
resource "google_compute_address" "gitlab-com-static-ip" {
  name        = "gitlab-com"
  description = "gitlab-com"
}
294

295 296 297 298
# IP address for NAT
resource "google_compute_address" "gke-cloud-nat-ip" {
  name        = "gitlab-gke"
  description = "gitlab-gke"
299 300
}

301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336
resource "google_compute_router" "nat-router" {
  name    = "gitlab-gke"
  network = "${module.network.self_link}"
}

resource "google_compute_router_nat" "gke-nat" {
  name                               = "gitlab-gke"
  router                             = "${google_compute_router.nat-router.name}"
  nat_ip_allocate_option             = "MANUAL_ONLY"
  nat_ips                            = ["${google_compute_address.gke-cloud-nat-ip.self_link}"]
  source_subnetwork_ip_ranges_to_nat = "LIST_OF_SUBNETWORKS"

  subnetwork {
    name                    = "${module.gitlab-gke.subnetwork_self_link}"
    source_ip_ranges_to_nat = ["ALL_IP_RANGES"]
  }
}

module "gitlab-gke" {
  environment            = "${var.environment}"
  name                   = "gitlab-gke"
  vpc                    = "${module.network.self_link}"
  source                 = "git::ssh://[email protected]/gitlab-com/gl-infra/terraform-modules/google/gke.git?ref=v4.0.0"
  ip_cidr_range          = "${var.subnetworks["gitlab-gke"]}"
  disable_network_policy = "false"
  dns_zone_name          = "${var.dns_zone_name}"
  machine_type           = "${var.machine_types["gitlab-gke"]}"
  max_node_count         = "3"
  node_disk_size         = "50"
  preemptible            = "true"
  private_cluster        = "true"
  private_master_cidr    = "${var.master_cidr_subnets["gitlab-gke"]}"
  project                = "${var.project}"
  region                 = "${var.region}"
  pod_ip_cidr_range      = "${var.subnetworks["gitlab-gke-pod-cidr"]}"
  service_ip_cidr_range  = "${var.subnetworks["gitlab-gke-service-cidr"]}"
John Jarvis's avatar
John Jarvis committed
337
}
John Jarvis's avatar
John Jarvis committed
338

John Jarvis's avatar
John Jarvis committed
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379
##################################
#
#  Pubsubbeat for GKE
#  This adds a single beat for logs
#  from GKE
#
#  Machines for running the beats
#  that consume logs from pubsub
#  and send them to elastic cloud
#
#  You must have a chef role with the
#  following format:
#     role[<env>-infra-pubsubbeat-<beat_name>]
#
##################################

module "pubsubbeat" {
  bootstrap_version     = "${var.bootstrap_script_version}"
  chef_provision        = "${var.chef_provision}"
  dns_zone_name         = "${var.dns_zone_name}"
  environment           = "${var.environment}"
  health_check          = "tcp"
  ip_cidr_range         = "${var.subnetworks["pubsubbeat"]}"
  machine_types         = ["n1-standard-1"]
  names                 = ["gke"]
  project               = "${var.project}"
  public_ports          = "${var.public_ports["pubsubbeat"]}"
  region                = "${var.region}"
  service_account_email = "${var.service_account_email}"
  service_port          = 22
  source                = "git::ssh://[email protected]/gitlab-com/gl-infra/terraform-modules/google/pubsubbeat.git?ref=v1.0.6"
  tier                  = "inf"
  use_new_node_name     = true
  vpc                   = "${module.network.self_link}"
}

resource "google_logging_project_sink" "pubsub" {
  name = "${var.environment}-pubsub-sink"

  # There is only a single pubsub topic for gke
  destination = "pubsub.googleapis.com/projects/${var.project}/topics/${module.pubsubbeat.topic_names[0]}"
380
  filter      = "resource.labels.cluster_name = pre-gitlab-gke"
John Jarvis's avatar
John Jarvis committed
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433

  # Use a unique writer (creates a unique service account used for writing)
  unique_writer_identity = true
  depends_on             = ["module.pubsubbeat"]
}

resource "google_project_iam_binding" "log-writer" {
  role = "roles/pubsub.publisher"

  members = [
    "${google_logging_project_sink.pubsub.writer_identity}",
  ]
}

##################################
#
#  Log Proxy
#
#################################

module "proxy-iap" {
  environment          = "${var.environment}"
  source               = "git::ssh://[email protected]/gitlab-com/gl-infra/terraform-modules/google/web-iap.git?ref=v1.0.0"
  name                 = "proxy"
  project              = "${var.project}"
  region               = "${var.region}"
  gitlab_zone_id       = "${var.gitlab_net_zone_id}"
  cert_link            = "${var.monitoring_cert_link}"
  backend_service_link = "${module.proxy.google_compute_backend_service_iap_self_link}"
  web_ip_fqdn          = "log.pre.gitlab.net"
  service_ports        = ["443", "80", "9090"]
}

module "proxy" {
  bootstrap_version     = "${var.bootstrap_script_version}"
  chef_provision        = "${var.chef_provision}"
  chef_run_list         = "\"role[${var.environment}-infra-proxy]\""
  dns_zone_name         = "${var.dns_zone_name}"
  enable_iap            = true
  environment           = "${var.environment}"
  health_check          = "http"
  service_path          = "/app/kibana"
  ip_cidr_range         = "${var.subnetworks["proxy"]}"
  machine_type          = "${var.machine_types["proxy"]}"
  name                  = "proxy"
  node_count            = 1
  oauth2_client_id      = "${var.oauth2_client_id_log_proxy}"
  oauth2_client_secret  = "${var.oauth2_client_secret_log_proxy}"
  project               = "${var.project}"
  public_ports          = "${var.public_ports["proxy"]}"
  region                = "${var.region}"
  service_account_email = "${var.service_account_email}"
  service_port          = "9090"
434
  source                = "git::ssh://[email protected]/gitlab-com/gl-infra/terraform-modules/google/generic-sv-with-group.git?ref=v1.0.4"
John Jarvis's avatar
John Jarvis committed
435 436 437 438 439
  tier                  = "inf"
  use_new_node_name     = true
  vpc                   = "${module.network.self_link}"
}

John Jarvis's avatar
John Jarvis committed
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458
##################################
#
#  External HAProxy LoadBalancer
#
##################################

module "fe-lb" {
  backend_service_type   = "regional"
  bootstrap_version      = "${var.bootstrap_script_version}"
  chef_provision         = "${var.chef_provision}"
  chef_run_list          = "\"role[${var.environment}-base-lb-fe]\""
  create_backend_service = false
  dns_zone_name          = "${var.dns_zone_name}"
  environment            = "${var.environment}"
  health_check           = "http"
  ip_cidr_range          = "${var.subnetworks["fe-lb"]}"
  machine_type           = "${var.machine_types["fe-lb"]}"
  name                   = "fe"
  node_count             = "${var.node_count["fe-lb"]}"
459
  os_boot_image          = "ubuntu-os-cloud/ubuntu-1804-bionic-v20190404"
John Jarvis's avatar
John Jarvis committed
460 461 462 463 464 465
  project                = "${var.project}"
  public_ports           = "${var.public_ports["fe-lb"]}"
  region                 = "${var.region}"
  service_account_email  = "${var.service_account_email}"
  service_path           = "/-/available-https"
  service_port           = 8002
466
  source                 = "git::ssh://[email protected]/gitlab-com/gl-infra/terraform-modules/google/generic-sv-with-group.git?ref=v1.0.4"
John Jarvis's avatar
John Jarvis committed
467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494
  tier                   = "lb"
  use_new_node_name      = true
  vpc                    = "${module.network.self_link}"
}

##################################
#
#  External HAProxy LoadBalancer Pages
#
##################################

module "fe-lb-pages" {
  bootstrap_version      = "${var.bootstrap_script_version}"
  chef_provision         = "${var.chef_provision}"
  chef_run_list          = "\"role[${var.environment}-base-lb-pages]\""
  create_backend_service = false
  dns_zone_name          = "${var.dns_zone_name}"
  environment            = "${var.environment}"
  health_check           = "http"
  ip_cidr_range          = "${var.subnetworks["fe-lb-pages"]}"
  machine_type           = "${var.machine_types["fe-lb"]}"
  name                   = "fe-pages"
  node_count             = "${var.node_count["fe-lb-pages"]}"
  project                = "${var.project}"
  public_ports           = "${var.public_ports["fe-lb"]}"
  region                 = "${var.region}"
  service_account_email  = "${var.service_account_email}"
  service_port           = 7331
495
  source                 = "git::ssh://[email protected]/gitlab-com/gl-infra/terraform-modules/google/generic-sv-with-group.git?ref=v1.0.4"
John Jarvis's avatar
John Jarvis committed
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519
  tier                   = "lb"
  use_new_node_name      = true
  vpc                    = "${module.network.self_link}"
}

##################################
#
#  External HAProxy LoadBalancer Registry
#
##################################

module "fe-lb-registry" {
  bootstrap_version      = "${var.bootstrap_script_version}"
  chef_provision         = "${var.chef_provision}"
  chef_run_list          = "\"role[${var.environment}-base-lb-registry]\""
  create_backend_service = false
  dns_zone_name          = "${var.dns_zone_name}"
  environment            = "${var.environment}"
  health_check           = "http"
  ip_cidr_range          = "${var.subnetworks["fe-lb-registry"]}"
  machine_type           = "${var.machine_types["fe-lb"]}"
  name                   = "fe-registry"
  node_count             = "${var.node_count["fe-lb-registry"]}"
  project                = "${var.project}"
520
  os_boot_image          = "ubuntu-os-cloud/ubuntu-1804-bionic-v20190404"
John Jarvis's avatar
John Jarvis committed
521 522 523 524 525
  public_ports           = "${var.public_ports["fe-lb"]}"
  region                 = "${var.region}"
  service_account_email  = "${var.service_account_email}"
  service_path           = "/-/available-https"
  service_port           = 8002
526
  source                 = "git::ssh://[email protected]/gitlab-com/gl-infra/terraform-modules/google/generic-sv-with-group.git?ref=v1.0.4"
John Jarvis's avatar
John Jarvis committed
527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611
  tier                   = "lb"
  use_new_node_name      = true
  vpc                    = "${module.network.self_link}"
}

##################################
#
#  GCP TCP LoadBalancers
#
##################################

#### Load balancer for the main site
module "gcp-tcp-lb" {
  environment            = "${var.environment}"
  forwarding_port_ranges = "${var.tcp_lbs["forwarding_port_ranges"]}"
  fqdns                  = "${var.lb_fqdns}"
  gitlab_zone_id         = "${var.gitlab_com_zone_id}"
  health_check_ports     = "${var.tcp_lbs["health_check_ports"]}"
  instances              = ["${module.fe-lb.instances_self_link}"]
  lb_count               = "${length(var.tcp_lbs["names"])}"
  name                   = "gcp-tcp-lb"
  names                  = "${var.tcp_lbs["names"]}"
  project                = "${var.project}"
  region                 = "${var.region}"
  source                 = "git::ssh://[email protected]/gitlab-com/gl-infra/terraform-modules/google/tcp-lb.git?ref=v1.0.0"
  targets                = ["fe"]
}

#### Load balancer for pages
module "gcp-tcp-lb-pages" {
  environment            = "${var.environment}"
  forwarding_port_ranges = "${var.tcp_lbs_pages["forwarding_port_ranges"]}"
  fqdns                  = "${var.lb_fqdns_pages}"
  gitlab_zone_id         = "${var.gitlab_io_zone_id}"
  health_check_ports     = "${var.tcp_lbs_pages["health_check_ports"]}"
  instances              = ["${module.fe-lb-pages.instances_self_link}"]
  lb_count               = "${length(var.tcp_lbs_pages["names"])}"
  name                   = "gcp-tcp-lb-pages"
  names                  = "${var.tcp_lbs_pages["names"]}"
  project                = "${var.project}"
  region                 = "${var.region}"
  source                 = "git::ssh://[email protected]/gitlab-com/gl-infra/terraform-modules/google/tcp-lb.git?ref=v1.0.0"
  targets                = ["fe-pages"]
}

#### Load balancer for registry
module "gcp-tcp-lb-registry" {
  environment            = "${var.environment}"
  forwarding_port_ranges = "${var.tcp_lbs_registry["forwarding_port_ranges"]}"
  fqdns                  = "${var.lb_fqdns_registry}"
  gitlab_zone_id         = "${var.gitlab_com_zone_id}"
  health_check_ports     = "${var.tcp_lbs_registry["health_check_ports"]}"
  instances              = ["${module.fe-lb-registry.instances_self_link}"]
  lb_count               = "${length(var.tcp_lbs_registry["names"])}"
  name                   = "gcp-tcp-lb-registry"
  names                  = "${var.tcp_lbs_registry["names"]}"
  project                = "${var.project}"
  region                 = "${var.region}"
  source                 = "git::ssh://[email protected]/gitlab-com/gl-infra/terraform-modules/google/tcp-lb.git?ref=v1.0.0"
  targets                = ["fe-registry"]
}

##################################
#
#  Deploy
#
##################################

module "deploy" {
  bootstrap_version     = "${var.bootstrap_script_version}"
  chef_provision        = "${var.chef_provision}"
  chef_run_list         = "\"role[${var.environment}-base-deploy-node]\""
  dns_zone_name         = "${var.dns_zone_name}"
  egress_ports          = "${var.deploy_egress_ports}"
  environment           = "${var.environment}"
  health_check          = "tcp"
  ip_cidr_range         = "${var.subnetworks["deploy"]}"
  machine_type          = "${var.machine_types["deploy"]}"
  name                  = "deploy"
  node_count            = "${var.node_count["deploy"]}"
  project               = "${var.project}"
  public_ports          = "${var.public_ports["deploy"]}"
  region                = "${var.region}"
  service_account_email = "${var.service_account_email}"
  service_port          = 22
612
  source                = "git::ssh://[email protected]/gitlab-com/gl-infra/terraform-modules/google/generic-sv-with-group.git?ref=v1.0.4"
John Jarvis's avatar
John Jarvis committed
613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640
  tier                  = "sv"
  use_external_ip       = true
  use_new_node_name     = true
  vpc                   = "${module.network.self_link}"
}

##################################
#
#  registry front-end
#
#################################

module "registry" {
  bootstrap_version     = "${var.bootstrap_script_version}"
  chef_provision        = "${var.chef_provision}"
  chef_run_list         = "\"role[${var.environment}-base-fe-registry]\""
  dns_zone_name         = "${var.dns_zone_name}"
  environment           = "${var.environment}"
  health_check          = "tcp"
  ip_cidr_range         = "${var.subnetworks["registry"]}"
  machine_type          = "${var.machine_types["registry"]}"
  name                  = "registry"
  node_count            = "${var.node_count["registry"]}"
  project               = "${var.project}"
  public_ports          = "${var.public_ports["registry"]}"
  region                = "${var.region}"
  service_account_email = "${var.service_account_email}"
  service_port          = 22
641
  source                = "git::ssh://[email protected]/gitlab-com/gl-infra/terraform-modules/google/generic-sv-with-group.git?ref=v1.0.4"
John Jarvis's avatar
John Jarvis committed
642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670
  tier                  = "sv"
  use_new_node_name     = true
  vpc                   = "${module.network.self_link}"
}

##################################
#
#  Web front-end
#
#################################

module "web" {
  bootstrap_version     = "${var.bootstrap_script_version}"
  chef_provision        = "${var.chef_provision}"
  chef_run_list         = "\"role[${var.environment}-base-fe-web]\""
  dns_zone_name         = "${var.dns_zone_name}"
  egress_ports          = "${var.egress_ports}"
  environment           = "${var.environment}"
  health_check          = "tcp"
  ip_cidr_range         = "${var.subnetworks["web"]}"
  machine_type          = "${var.machine_types["web"]}"
  name                  = "web"
  node_count            = "${var.node_count["web"]}"
  os_disk_type          = "pd-ssd"
  project               = "${var.project}"
  public_ports          = "${var.public_ports["web"]}"
  region                = "${var.region}"
  service_account_email = "${var.service_account_email}"
  service_port          = 443
671
  source                = "git::ssh://[email protected]/gitlab-com/gl-infra/terraform-modules/google/generic-sv-with-group.git?ref=v1.0.4"
John Jarvis's avatar
John Jarvis committed
672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699
  tier                  = "sv"
  use_new_node_name     = true
  vpc                   = "${module.network.self_link}"
}

##################################
#
#  API
#
#################################

module "api" {
  bootstrap_version     = "${var.bootstrap_script_version}"
  chef_provision        = "${var.chef_provision}"
  chef_run_list         = "\"role[${var.environment}-base-fe-api]\""
  dns_zone_name         = "${var.dns_zone_name}"
  environment           = "${var.environment}"
  health_check          = "tcp"
  ip_cidr_range         = "${var.subnetworks["api"]}"
  machine_type          = "${var.machine_types["api"]}"
  name                  = "api"
  node_count            = "${var.node_count["api"]}"
  os_disk_type          = "pd-ssd"
  project               = "${var.project}"
  public_ports          = "${var.public_ports["api"]}"
  region                = "${var.region}"
  service_account_email = "${var.service_account_email}"
  service_port          = 443
700
  source                = "git::ssh://[email protected]/gitlab-com/gl-infra/terraform-modules/google/generic-sv-with-group.git?ref=v1.0.4"
John Jarvis's avatar
John Jarvis committed
701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729
  tier                  = "sv"
  use_new_node_name     = true
  vpc                   = "${module.network.self_link}"
}

##################################
#
#  Git
#
##################################

module "git" {
  bootstrap_version     = "${var.bootstrap_script_version}"
  chef_provision        = "${var.chef_provision}"
  chef_run_list         = "\"role[${var.environment}-base-fe-git]\""
  dns_zone_name         = "${var.dns_zone_name}"
  egress_ports          = "${var.egress_ports}"
  environment           = "${var.environment}"
  health_check          = "tcp"
  ip_cidr_range         = "${var.subnetworks["git"]}"
  machine_type          = "${var.machine_types["git"]}"
  name                  = "git"
  node_count            = "${var.node_count["git"]}"
  os_disk_type          = "pd-ssd"
  project               = "${var.project}"
  public_ports          = "${var.public_ports["git"]}"
  region                = "${var.region}"
  service_account_email = "${var.service_account_email}"
  service_port          = 22
730
  source                = "git::ssh://[email protected]/gitlab-com/gl-infra/terraform-modules/google/generic-sv-with-group.git?ref=v1.0.4"
John Jarvis's avatar
John Jarvis committed
731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758
  tier                  = "sv"
  use_new_node_name     = true
  vpc                   = "${module.network.self_link}"
}

##################################
#
#  Pages web front-end
#
#################################

module "web-pages" {
  bootstrap_version     = "${var.bootstrap_script_version}"
  chef_provision        = "${var.chef_provision}"
  chef_run_list         = "\"role[${var.environment}-base-fe-web-pages]\""
  dns_zone_name         = "${var.dns_zone_name}"
  environment           = "${var.environment}"
  health_check          = "tcp"
  ip_cidr_range         = "${var.subnetworks["web-pages"]}"
  machine_type          = "${var.machine_types["web-pages"]}"
  name                  = "web-pages"
  node_count            = "${var.node_count["web-pages"]}"
  os_disk_type          = "pd-ssd"
  project               = "${var.project}"
  public_ports          = "${var.public_ports["web-pages"]}"
  region                = "${var.region}"
  service_account_email = "${var.service_account_email}"
  service_port          = 443
759
  source                = "git::ssh://[email protected]/gitlab-com/gl-infra/terraform-modules/google/generic-sv-with-group.git?ref=v1.0.4"
John Jarvis's avatar
John Jarvis committed
760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802
  tier                  = "sv"
  use_new_node_name     = true
  vpc                   = "${module.network.self_link}"
}

##################################
#
#  Sidekiq
#
##################################

module "sidekiq" {
  bootstrap_version                   = "${var.bootstrap_script_version}"
  chef_provision                      = "${var.chef_provision}"
  chef_run_list                       = "\"role[${var.environment}-base-be-sidekiq-besteffort]\""
  dns_zone_name                       = "${var.dns_zone_name}"
  environment                         = "${var.environment}"
  ip_cidr_range                       = "${var.subnetworks["sidekiq"]}"
  machine_type                        = "${var.machine_types["sidekiq-besteffort"]}"
  name                                = "sidekiq"
  os_disk_type                        = "pd-ssd"
  project                             = "${var.project}"
  public_ports                        = "${var.public_ports["sidekiq"]}"
  region                              = "${var.region}"
  service_account_email               = "${var.service_account_email}"
  sidekiq_asap_count                  = "0"
  sidekiq_asap_instance_type          = "none"
  sidekiq_besteffort_count            = "${var.node_count["sidekiq-besteffort"]}"
  sidekiq_besteffort_instance_type    = "${var.machine_types["sidekiq-besteffort"]}"
  sidekiq_elasticsearch_count         = "0"
  sidekiq_elasticsearch_instance_type = "none"
  sidekiq_import_count                = "0"
  sidekiq_import_instance_type        = "none"
  sidekiq_pages_count                 = "0"
  sidekiq_pages_instance_type         = "none"
  sidekiq_pipeline_count              = "0"
  sidekiq_pipeline_instance_type      = "none"
  sidekiq_pullmirror_count            = "0"
  sidekiq_pullmirror_instance_type    = "none"
  sidekiq_realtime_count              = "0"
  sidekiq_realtime_instance_type      = "none"
  sidekiq_traces_count                = "0"
  sidekiq_traces_instance_type        = "none"
803
  source                              = "git::ssh://[email protected]/gitlab-com/gl-infra/terraform-modules/google/generic-sv-sidekiq.git?ref=v1.0.4"
John Jarvis's avatar
John Jarvis committed
804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832
  tier                                = "sv"
  use_new_node_name                   = true
  vpc                                 = "${module.network.self_link}"
}

##################################
#
#  Gitaly node
#
##################################

module "gitaly" {
  bootstrap_version     = "${var.bootstrap_script_version}"
  chef_provision        = "${var.chef_provision}"
  chef_run_list         = "\"role[${var.environment}-base-be-gitaly]\""
  dns_zone_name         = "${var.dns_zone_name}"
  egress_ports          = "${var.egress_ports}"
  environment           = "${var.environment}"
  health_check          = "tcp"
  ip_cidr_range         = "${var.subnetworks["gitaly"]}"
  machine_type          = "${var.machine_types["gitaly"]}"
  name                  = "gitaly"
  node_count            = "${var.node_count["gitaly"]}"
  os_disk_type          = "pd-ssd"
  project               = "${var.project}"
  public_ports          = "${var.public_ports["gitaly"]}"
  region                = "${var.region}"
  service_account_email = "${var.service_account_email}"
  service_port          = 22
833
  source                = "git::ssh://[email protected]/gitlab-com/gl-infra/terraform-modules/google/generic-sv-with-group.git?ref=v1.0.4"
John Jarvis's avatar
John Jarvis committed
834 835 836 837
  tier                  = "sv"
  use_new_node_name     = true
  vpc                   = "${module.network.self_link}"
}
838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856

module "thanos-compact" {
  bootstrap_version     = "${var.bootstrap_script_version}"
  chef_provision        = "${var.chef_provision}"
  chef_run_list         = "\"role[${var.environment}-infra-thanos-compact]\""
  data_disk_size        = 200
  dns_zone_name         = "${var.dns_zone_name}"
  egress_ports          = "${var.egress_ports}"
  environment           = "${var.environment}"
  ip_cidr_range         = "${var.subnetworks["thanos-compact"]}"
  machine_type          = "${var.machine_types["thanos"]}"
  monitoring_whitelist  = "${var.monitoring_whitelist_thanos}"
  name                  = "thanos-compact"
  node_count            = "${var.node_count["thanos"]}"
  persistent_disk_path  = "/opt/prometheus"
  project               = "${var.project}"
  public_ports          = "${var.public_ports["thanos"]}"
  region                = "${var.region}"
  service_account_email = "${var.service_account_email}"
Craig Furman's avatar
Craig Furman committed
857
  source                = "git::ssh://[email protected]/gitlab-com/gl-infra/terraform-modules/google/generic-stor.git?ref=v1.1.1"
858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880
  tier                  = "inf"
  use_new_node_name     = true
  vpc                   = "${module.network.self_link}"
}

module "thanos-store" {
  bootstrap_version     = "${var.bootstrap_script_version}"
  chef_provision        = "${var.chef_provision}"
  chef_run_list         = "\"role[${var.environment}-infra-thanos-store]\""
  data_disk_size        = 100
  dns_zone_name         = "${var.dns_zone_name}"
  egress_ports          = "${var.egress_ports}"
  environment           = "${var.environment}"
  ip_cidr_range         = "${var.subnetworks["thanos-store"]}"
  machine_type          = "${var.machine_types["thanos"]}"
  monitoring_whitelist  = "${var.monitoring_whitelist_thanos}"
  name                  = "thanos-store"
  node_count            = "${var.node_count["thanos"]}"
  persistent_disk_path  = "/opt/prometheus"
  project               = "${var.project}"
  public_ports          = "${var.public_ports["thanos"]}"
  region                = "${var.region}"
  service_account_email = "${var.service_account_email}"
Craig Furman's avatar
Craig Furman committed
881
  source                = "git::ssh://[email protected]/gitlab-com/gl-infra/terraform-modules/google/generic-stor.git?ref=v1.1.1"
882 883 884 885
  tier                  = "inf"
  use_new_node_name     = true
  vpc                   = "${module.network.self_link}"
}