|
| 1 | +resource "google_cloud_run_v2_service" "metabase-staging" { |
| 2 | + name = "metabase-staging" |
| 3 | + location = "us-west2" |
| 4 | + deletion_protection = false |
| 5 | + ingress = "INGRESS_TRAFFIC_ALL" |
| 6 | + |
| 7 | + traffic { |
| 8 | + type = "TRAFFIC_TARGET_ALLOCATION_TYPE_LATEST" |
| 9 | + percent = 100 |
| 10 | + } |
| 11 | + |
| 12 | + scaling { |
| 13 | + min_instance_count = 1 |
| 14 | + } |
| 15 | + |
| 16 | + template { |
| 17 | + service_account = data.terraform_remote_state.iam.outputs.google_service_account_metabase-service-account_email |
| 18 | + |
| 19 | + volumes { |
| 20 | + name = "cloudsql" |
| 21 | + cloud_sql_instance { |
| 22 | + instances = [google_sql_database_instance.metabase-staging.connection_name] |
| 23 | + } |
| 24 | + } |
| 25 | + |
| 26 | + containers { |
| 27 | + image = "us-west2-docker.pkg.dev/cal-itp-data-infra-staging/ghcr/cal-itp/data-infra/metabase:latest" |
| 28 | + |
| 29 | + resources { |
| 30 | + limits = { |
| 31 | + cpu = "1" |
| 32 | + memory = "2048Mi" |
| 33 | + } |
| 34 | + } |
| 35 | + |
| 36 | + ports { |
| 37 | + container_port = 3000 |
| 38 | + } |
| 39 | + |
| 40 | + startup_probe { |
| 41 | + timeout_seconds = 2 |
| 42 | + period_seconds = 5 |
| 43 | + failure_threshold = 10 |
| 44 | + |
| 45 | + http_get { |
| 46 | + path = "/" |
| 47 | + port = 3000 |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + liveness_probe { |
| 52 | + http_get { |
| 53 | + path = "/" |
| 54 | + port = 3000 |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | + volume_mounts { |
| 59 | + name = "cloudsql" |
| 60 | + mount_path = "/cloudsql" |
| 61 | + } |
| 62 | + |
| 63 | + env { |
| 64 | + name = "MB_DB_TYPE" |
| 65 | + value = "postgres" |
| 66 | + } |
| 67 | + |
| 68 | + env { |
| 69 | + name = "MB_DB_DBNAME" |
| 70 | + value = google_sql_database.metabase-staging.name |
| 71 | + } |
| 72 | + |
| 73 | + env { |
| 74 | + name = "MB_DB_HOST" |
| 75 | + value = "127.0.0.1" |
| 76 | + } |
| 77 | + |
| 78 | + env { |
| 79 | + name = "MB_DB_USER" |
| 80 | + value = google_sql_user.metabase-staging.name |
| 81 | + } |
| 82 | + |
| 83 | + env { |
| 84 | + name = "MB_DB_PASS" |
| 85 | + value_source { |
| 86 | + secret_key_ref { |
| 87 | + secret = google_secret_manager_secret.metabase-staging-password.secret_id |
| 88 | + version = "latest" |
| 89 | + } |
| 90 | + } |
| 91 | + } |
| 92 | + |
| 93 | + env { |
| 94 | + name = "JAVA_OPTS" |
| 95 | + value = "-Xmx2048m" |
| 96 | + } |
| 97 | + } |
| 98 | + } |
| 99 | +} |
| 100 | + |
| 101 | +resource "google_cloud_run_service_iam_binding" "metabase-staging" { |
| 102 | + location = google_cloud_run_v2_service.metabase-staging.location |
| 103 | + service = google_cloud_run_v2_service.metabase-staging.name |
| 104 | + role = "roles/run.invoker" |
| 105 | + members = ["allUsers"] |
| 106 | +} |
| 107 | + |
| 108 | +resource "google_compute_region_network_endpoint_group" "metabase-staging" { |
| 109 | + name = "metabase-staging" |
| 110 | + network_endpoint_type = "SERVERLESS" |
| 111 | + region = google_cloud_run_v2_service.metabase-staging.location |
| 112 | + cloud_run { |
| 113 | + service = google_cloud_run_v2_service.metabase-staging.name |
| 114 | + } |
| 115 | +} |
| 116 | + |
| 117 | +module "lb-http" { |
| 118 | + source = "GoogleCloudPlatform/lb-http/google//modules/serverless_negs" |
| 119 | + version = "~> 14.0" |
| 120 | + |
| 121 | + name = "metabase-staging" |
| 122 | + project = "cal-itp-data-infra-staging" |
| 123 | + |
| 124 | + ssl = true |
| 125 | + managed_ssl_certificate_domains = [local.domain] |
| 126 | + https_redirect = true |
| 127 | + |
| 128 | + address = google_compute_global_address.metabase-staging.address |
| 129 | + create_address = false |
| 130 | + |
| 131 | + backends = { |
| 132 | + metabase = { |
| 133 | + groups = [] |
| 134 | + serverless_neg_backends = [ |
| 135 | + { |
| 136 | + "region" : "us-west2", |
| 137 | + "type" : "cloud-run", |
| 138 | + "service" : { |
| 139 | + "name" : google_cloud_run_v2_service.metabase-staging.name |
| 140 | + } |
| 141 | + } |
| 142 | + ] |
| 143 | + |
| 144 | + health_check = { |
| 145 | + request_path = "/" |
| 146 | + protocol = "HTTP" |
| 147 | + port = 80 |
| 148 | + } |
| 149 | + |
| 150 | + enable_cdn = false |
| 151 | + |
| 152 | + iap_config = { |
| 153 | + enable = false |
| 154 | + } |
| 155 | + |
| 156 | + log_config = { |
| 157 | + enable = false |
| 158 | + } |
| 159 | + } |
| 160 | + } |
| 161 | +} |
0 commit comments