|
| 1 | +# FIXME: For real deployment we should store the terraform state |
| 2 | +# in cloud storage rather than just the current directory, terraform |
| 3 | +# supports Azure blob storage directly. This means configuration |
| 4 | +# doesn't need to be on a single machine somewhere. |
| 5 | +# |
| 6 | +# See https://developer.hashicorp.com/terraform/language/settings/backends/gcs |
| 7 | +# |
| 8 | +#terraform { |
| 9 | +# backend "gcs" { |
| 10 | +# resource_group_name = "kernelci-tf-storage" |
| 11 | +# storage_account_name = "kernelci-tf" |
| 12 | +# container_name = "tfstate" |
| 13 | +# key = "workers.terraform.tfstate" |
| 14 | +# } |
| 15 | +#} |
| 16 | + |
| 17 | +#variable "gke_username" { |
| 18 | +# default = "" |
| 19 | +# description = "gke username" |
| 20 | +#} |
| 21 | + |
| 22 | +#variable "gke_password" { |
| 23 | +# default = "" |
| 24 | +# description = "gke password" |
| 25 | +#} |
| 26 | + |
| 27 | +locals { |
| 28 | + regions = toset([ |
| 29 | + "us-central1", |
| 30 | + "europe-west2", |
| 31 | + ]) |
| 32 | +} |
| 33 | + |
| 34 | +# GKE cluster |
| 35 | +resource "google_container_cluster" "primary" { |
| 36 | + for_each = local.regions |
| 37 | + |
| 38 | + name = "${each.key}-workers" |
| 39 | + location = each.key |
| 40 | + |
| 41 | + # We can't create a cluster with no node pool defined, but we want to only use |
| 42 | + # separately managed node pools. So we create the smallest possible default |
| 43 | + # node pool and immediately delete it. |
| 44 | + remove_default_node_pool = true |
| 45 | + initial_node_count = 1 |
| 46 | + |
| 47 | + network = "${each.key}-vpc" |
| 48 | + subnetwork = "${each.key}-subnet" |
| 49 | +} |
| 50 | + |
| 51 | +# Smaller nodes for most jobs |
| 52 | +resource "google_container_node_pool" "small_nodes" { |
| 53 | + for_each = local.regions |
| 54 | + |
| 55 | + name = "${each.key}-small-node-pool" |
| 56 | + location = each.key |
| 57 | + cluster = "${each.key}-workers" |
| 58 | + |
| 59 | + node_config { |
| 60 | + oauth_scopes = [ |
| 61 | + "https://www.googleapis.com/auth/logging.write", |
| 62 | + "https://www.googleapis.com/auth/monitoring", |
| 63 | + ] |
| 64 | + |
| 65 | + labels = { |
| 66 | + "kernelci/worker" = "worker" |
| 67 | + "kernelci/worker-size" = "small" |
| 68 | + } |
| 69 | + |
| 70 | + # Standard machine, 8 vCPUs, 30G memory |
| 71 | + machine_type = "n1-standard-8" |
| 72 | + preemptible = true |
| 73 | + spot = true |
| 74 | + tags = [ |
| 75 | + "kernelci/worker", |
| 76 | + "kernelci/small-worker" |
| 77 | + ] |
| 78 | + |
| 79 | + metadata = { |
| 80 | + disable-legacy-endpoints = "true" |
| 81 | + } |
| 82 | + } |
| 83 | + |
| 84 | + autoscaling { |
| 85 | + min_node_count = 1 |
| 86 | + max_node_count = 10 |
| 87 | + } |
| 88 | +} |
| 89 | + |
| 90 | +# Bigger nodes for all*config jobs |
| 91 | +resource "google_container_node_pool" "big_nodes" { |
| 92 | + for_each = local.regions |
| 93 | + |
| 94 | + name = "${each.key}-big-node-pool" |
| 95 | + location = each.key |
| 96 | + cluster = "${each.key}-workers" |
| 97 | + |
| 98 | + node_config { |
| 99 | + oauth_scopes = [ |
| 100 | + "https://www.googleapis.com/auth/logging.write", |
| 101 | + "https://www.googleapis.com/auth/monitoring", |
| 102 | + ] |
| 103 | + |
| 104 | + labels = { |
| 105 | + "kernelci/worker" = "worker" |
| 106 | + "kernelci/worker-size" = "big" |
| 107 | + } |
| 108 | + |
| 109 | + # Standard machine, 32 vCPUs, 128G (?) memory |
| 110 | + machine_type = "n2-standard-32" |
| 111 | + preemptible = true |
| 112 | + spot = true |
| 113 | + tags = [ |
| 114 | + "kernelci/worker", |
| 115 | + "kernelci/big-worker" |
| 116 | + ] |
| 117 | + |
| 118 | + metadata = { |
| 119 | + disable-legacy-endpoints = "true" |
| 120 | + } |
| 121 | + } |
| 122 | + |
| 123 | + autoscaling { |
| 124 | + min_node_count = 1 |
| 125 | + max_node_count = 10 |
| 126 | + } |
| 127 | +} |
0 commit comments