Skip to content

Commit

Permalink
URL mapping for distributor in CI environment (#88)
Browse files Browse the repository at this point in the history
This is mapped at api.transpareny.dev/distributor-ci/.
All other resources should be mapped at their old location.
  • Loading branch information
mhutchinson authored Feb 7, 2024
1 parent e5b71d4 commit c12ce2c
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 19 deletions.
72 changes: 59 additions & 13 deletions deployment/api_transparency_dev/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,36 @@ module "lb-http" {
enable_ipv6 = true

backends = {
default = {
description = "Distributor API backend"
prod = {
description = "Distributor API backend (prod)"
protocol = "HTTPS"
port_name = "https"
port = 443
groups = [
{
group = google_compute_global_network_endpoint_group.distributor.id
group = google_compute_global_network_endpoint_group.distributor_prod.id
}
]

health_check = null

enable_cdn = false

iap_config = {
enable = false
}
log_config = {
enable = false
}
}
ci = {
description = "Distributor API backend (ci)"
protocol = "HTTPS"
port_name = "https"
port = 443
groups = [
{
group = google_compute_global_network_endpoint_group.distributor_ci.id
}
]

Expand Down Expand Up @@ -114,10 +136,22 @@ resource "google_compute_url_map" "default" {
]
route_action {
url_rewrite {
host_rewrite = var.distributor_host
host_rewrite = var.distributor_prod_host
}
}
service = module.lb-http.backend_services["prod"].id
}
path_rule {
paths = [
"/distributor-ci/*"
]
route_action {
url_rewrite {
path_prefix_rewrite = "/distributor/"
host_rewrite = var.distributor_ci_host
}
}
service = module.lb-http.backend_services["default"].id
service = module.lb-http.backend_services["ci"].id
}

#####
Expand Down Expand Up @@ -204,18 +238,30 @@ resource "google_compute_backend_bucket" "firmware_artefacts_ci_1" {
}


resource "google_compute_global_network_endpoint_group" "distributor" {
name = "distributor"
resource "google_compute_global_network_endpoint_group" "distributor_prod" {
name = "distributor-prod"
project = var.project_id
provider = google-beta
default_port = var.distributor_prod_port
network_endpoint_type = "INTERNET_FQDN_PORT"
}
resource "google_compute_global_network_endpoint_group" "distributor_ci" {
name = "distributor-ci"
project = var.project_id
provider = google-beta
default_port = var.distributor_port
default_port = var.distributor_ci_port
network_endpoint_type = "INTERNET_FQDN_PORT"
}

resource "google_compute_global_network_endpoint" "distributor" {
global_network_endpoint_group = google_compute_global_network_endpoint_group.distributor.name
port = var.distributor_port
fqdn = var.distributor_host
resource "google_compute_global_network_endpoint" "distributor_prod" {
global_network_endpoint_group = google_compute_global_network_endpoint_group.distributor_prod.name
port = var.distributor_prod_port
fqdn = var.distributor_prod_host
}
resource "google_compute_global_network_endpoint" "distributor_ci" {
global_network_endpoint_group = google_compute_global_network_endpoint_group.distributor_ci.name
port = var.distributor_ci_port
fqdn = var.distributor_ci_host
}

## Terraform keys
Expand All @@ -242,4 +288,4 @@ resource "google_compute_global_network_endpoint" "distributor" {
# default_kms_key_name = google_kms_crypto_key.terraform_state_bucket.id
# }
# uniform_bucket_level_access = true
#}
#}
9 changes: 7 additions & 2 deletions deployment/api_transparency_dev/terraform.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,10 @@ serve_domain = "api.transparency.dev"

lb_name = "transparency-dev-lb"

distributor_host = "distributor-service-oxxl2d5jeq-uc.a.run.app"
distributor_port = 443
# TODO(mhutchinson): this is the old env and should be switched to the following
# distributor_prod_host = "distributor-service-prod-oxxl2d5jeq-uc.a.run.app"
distributor_prod_host = "distributor-service-oxxl2d5jeq-uc.a.run.app"
distributor_prod_port = 443

distributor_ci_host = "distributor-service-ci-oxxl2d5jeq-uc.a.run.app"
distributor_ci_port = 443
15 changes: 11 additions & 4 deletions deployment/api_transparency_dev/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,18 @@ variable "tls" {
type = bool
}

variable "distributor_host" {
description = "Host name serving distributor service API"
variable "distributor_prod_host" {
description = "Host name serving distributor service API (prod)"
}
variable "distributor_port" {
description = "Port on distributor_host where distributor service API is served"
variable "distributor_prod_port" {
description = "Port on distributor_host where distributor service API is served (prod)"
type = number
}
variable "distributor_ci_host" {
description = "Host name serving distributor service API (ci)"
}
variable "distributor_ci_port" {
description = "Port on distributor_host where distributor service API is served (ci)"
type = number
}

Expand Down

0 comments on commit c12ce2c

Please sign in to comment.