Skip to content

Commit

Permalink
Manually create url map to do weighted routing
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelkedar committed May 8, 2024
1 parent b0f0d5d commit c650a4d
Showing 1 changed file with 63 additions and 2 deletions.
65 changes: 63 additions & 2 deletions deployment/terraform/modules/osv/website.tf
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,13 @@ module "gclb" {

load_balancing_scheme = "EXTERNAL_MANAGED"

create_url_map = false
url_map = google_compute_url_map.website.id

backends = {
default = {
appengine = {
groups = [
{
# TODO(michaelkedar): Replace with Cloud Run when ready
group = google_compute_region_network_endpoint_group.appengine_neg.id
}
]
Expand All @@ -116,6 +118,32 @@ module "gclb" {
enable = false
}
}

cloudrun = {
groups = [
{
group = google_compute_region_network_endpoint_group.serverless_neg.id
}
]
protocol = "HTTPS"
enable_cdn = true
cdn_policy = {
cache_key_policy = {
include_host = true
include_protocol = true
include_query_string = true
}
signed_url_cache_max_age_sec = 0
}
connection_draining_timeout_sec = 1

iap_config = {
enable = false
}
log_config = {
enable = false
}
}
}
}

Expand All @@ -137,6 +165,39 @@ resource "google_compute_region_network_endpoint_group" "appengine_neg" {
app_engine {}
}

resource "google_compute_url_map" "website" {
project = var.project_id
name = "website-url-map"
default_service = module.gclb.backend_services.appengine.id

host_rule {
hosts = ["*"]
path_matcher = "allpaths"
}

path_matcher {
name = "allpaths"
default_service = module.gclb.backend_services.appengine.id
route_rules {
priority = 1
match_rules {
prefix_match = "/"
}
route_action {
# TODO(michaelkedar): adjust weights, then remove appengine fully migrated
weighted_backend_services {
backend_service = module.gclb.backend_services.appengine.id
weight = 100
}
weighted_backend_services {
backend_service = module.gclb.backend_services.cloudrun.id
weight = 0
}
}
}
}
}

# Output all the DNS records required for the website in one place.
output "website_dns_records" {
description = "DNS records that need to be created for the osv.dev website"
Expand Down

0 comments on commit c650a4d

Please sign in to comment.