Skip to content

Commit ccde9e7

Browse files
authored
Merge pull request #54 from cal-itp/mov/37-terraform-load-balancer
Analyst can log into staging with DOT email
2 parents c094e7c + 08f4127 commit ccde9e7

File tree

2 files changed

+141
-5
lines changed

2 files changed

+141
-5
lines changed

iac/secrets.tf

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,48 @@ resource "google_secret_manager_secret_version" "cal-bc-staging-database-url" {
2929
secret = google_secret_manager_secret.cal-bc-staging-database-url.name
3030
secret_data_wo = "postgres://${google_sql_user.cal-bc-staging.name}:${random_password.cal-bc-staging-database.result}@//cloudsql/${google_sql_database_instance.cal-bc-staging.project}:${google_sql_database_instance.cal-bc-staging.region}:${google_sql_database_instance.cal-bc-staging.name}/${google_sql_database.cal-bc-staging.name}"
3131
}
32+
33+
resource "google_secret_manager_secret" "cal-bc-staging-azure-auth-client-id" {
34+
secret_id = "cal-bc-staging-azure-auth-client-id"
35+
replication {
36+
user_managed {
37+
replicas {
38+
location = "us-west2"
39+
}
40+
}
41+
}
42+
}
43+
44+
resource "google_secret_manager_secret_version" "cal-bc-staging-azure-auth-client-id" {
45+
secret = google_secret_manager_secret.cal-bc-staging-azure-auth-client-id.name
46+
}
47+
48+
resource "google_secret_manager_secret" "cal-bc-staging-azure-auth-client-secret" {
49+
secret_id = "cal-bc-staging-azure-auth-client-secret"
50+
replication {
51+
user_managed {
52+
replicas {
53+
location = "us-west2"
54+
}
55+
}
56+
}
57+
}
58+
59+
resource "google_secret_manager_secret_version" "cal-bc-staging-azure-auth-client-secret" {
60+
secret = google_secret_manager_secret.cal-bc-staging-azure-auth-client-secret.name
61+
}
62+
63+
resource "google_secret_manager_secret" "cal-bc-staging-azure-auth-directory-id" {
64+
secret_id = "cal-bc-staging-azure-auth-directory-id"
65+
replication {
66+
user_managed {
67+
replicas {
68+
location = "us-west2"
69+
}
70+
}
71+
}
72+
}
73+
74+
resource "google_secret_manager_secret_version" "cal-bc-staging-azure-auth-directory-id" {
75+
secret = google_secret_manager_secret.cal-bc-staging-azure-auth-directory-id.name
76+
}

iac/service.tf

Lines changed: 96 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ resource "google_cloud_run_v2_service" "cal-bc-staging" {
44
deletion_protection = false
55
ingress = "INGRESS_TRAFFIC_ALL"
66

7+
traffic {
8+
type = "TRAFFIC_TARGET_ALLOCATION_TYPE_LATEST"
9+
percent = 100
10+
}
11+
712
template {
813
service_account = data.terraform_remote_state.iam.outputs.google_service_account_cal-bc-service-account_email
914

@@ -44,12 +49,37 @@ resource "google_cloud_run_v2_service" "cal-bc-staging" {
4449
}
4550
}
4651
}
47-
}
48-
}
4952

50-
traffic {
51-
type = "TRAFFIC_TARGET_ALLOCATION_TYPE_LATEST"
52-
percent = 100
53+
env {
54+
name = "AZURE_AUTH__CLIENT_ID"
55+
value_source {
56+
secret_key_ref {
57+
secret = google_secret_manager_secret.cal-bc-staging-azure-auth-client-id.secret_id
58+
version = "latest"
59+
}
60+
}
61+
}
62+
63+
env {
64+
name = "AZURE_AUTH__CLIENT_SECRET"
65+
value_source {
66+
secret_key_ref {
67+
secret = google_secret_manager_secret.cal-bc-staging-azure-auth-client-secret.secret_id
68+
version = "latest"
69+
}
70+
}
71+
}
72+
73+
env {
74+
name = "AZURE_AUTH__DIRECTORY_ID"
75+
value_source {
76+
secret_key_ref {
77+
secret = google_secret_manager_secret.cal-bc-staging-azure-auth-directory-id.secret_id
78+
version = "latest"
79+
}
80+
}
81+
}
82+
}
5383
}
5484
}
5585

@@ -59,3 +89,64 @@ resource "google_cloud_run_service_iam_binding" "cal-bc-staging" {
5989
role = "roles/run.invoker"
6090
members = ["allUsers"]
6191
}
92+
93+
resource "google_compute_region_network_endpoint_group" "cal-bc-staging" {
94+
name = "cal-bc-staging"
95+
network_endpoint_type = "SERVERLESS"
96+
region = google_cloud_run_v2_service.cal-bc-staging.location
97+
cloud_run {
98+
service = google_cloud_run_v2_service.cal-bc-staging.name
99+
}
100+
}
101+
102+
resource "google_compute_global_address" "cal-bc-staging" {
103+
name = "cal-bc-staging-address"
104+
}
105+
106+
module "lb-http" {
107+
source = "GoogleCloudPlatform/lb-http/google//modules/serverless_negs"
108+
version = "~> 13.2"
109+
110+
name = "cal-bc-staging"
111+
project = "cal-itp-data-infra-staging"
112+
113+
ssl = true
114+
managed_ssl_certificate_domains = ["cal-bc-staging.dds.dot.ca.gov"]
115+
https_redirect = true
116+
117+
address = google_compute_global_address.cal-bc-staging.address
118+
create_address = false
119+
120+
backends = {
121+
default = {
122+
description = null
123+
124+
groups = []
125+
serverless_neg_backends = [
126+
{
127+
"region" : "us-west2",
128+
"type" : "cloud-run",
129+
"service" : {
130+
"name" : google_cloud_run_v2_service.cal-bc-staging.name
131+
}
132+
}
133+
]
134+
135+
health_check = {
136+
request_path = "/"
137+
protocol = "HTTP"
138+
port = 80
139+
}
140+
141+
enable_cdn = false
142+
143+
iap_config = {
144+
enable = false
145+
}
146+
147+
log_config = {
148+
enable = false
149+
}
150+
}
151+
}
152+
}

0 commit comments

Comments
 (0)