I have created an LB for the api gateway using google documentation and it works fine, but after creating it using the terraform recipe it gives me a 404 page not found
. These are the terraform resources for my load balancer. I have added the api gateway with terraform and it works for the LB added on gcloud console, and also tested the cloud function I have behind the api gateway and that works fine too. so I'm pretty sure the problem is with the LB. Any ideas anyone?
resource "google_compute_region_network_endpoint_group" "function_neg_us" {
name = var.neg_us_id.name
provider = google-beta
network_endpoint_type = "SERVERLESS"
region = var.neg_us_id.region #"us-east1"
serverless_deployment{
platform = "apigateway.googleapis.com"
resource = var.neg_us_id.gateway
}
}
resource "google_compute_backend_service" "webservers_backend_service_us" {
name = var.neg_us_id.backend_srv
timeout_sec = 30
provider = google-beta
connection_draining_timeout_sec = 0
load_balancing_scheme = "EXTERNAL"
protocol = "HTTPS"
log_config {
enable = true
sample_rate = 1
}
backend {
group = google_compute_region_network_endpoint_group.function_neg_us.id
balancing_mode = "UTILIZATION"
}
}
resource "google_compute_url_map" "lb_us" {
name = "url-map-us"
provider = google-beta
default_service = google_compute_backend_service.webservers_backend_service_us.id
host_rule {
hosts = [var.domain_name_us]
path_matcher = "us-predictions"
}
path_matcher {
name = "us-predictions"
default_service = google_compute_backend_service.webservers_backend_service_us.id
}
}
resource "google_compute_managed_ssl_certificate" "lb_ssl_cert_us" {
name = "us-predictions-test-terraform"
managed {
domains = [var.domain_name_us]
}
}
resource "google_compute_target_https_proxy" "lb_us_proxy" {
name = "us-https-proxy-test-terraform"
url_map = google_compute_url_map.lb_us.id
provider = google-beta
ssl_certificates = [
google_compute_managed_ssl_certificate.lb_ssl_cert_us.id
]
depends_on = [
google_compute_managed_ssl_certificate.lb_ssl_cert_us
]
}
# reserved IP address 8
resource "google_compute_global_address" "ip_address_us" {
name = "ssl-proxy-xlb-ip-terraform-us"
}
resource "google_compute_global_forwarding_rule" "rule_us" {
name = "ssl-proxy-xlb-forwarding-rule-us"
provider = google-beta
ip_protocol = "TCP"
load_balancing_scheme = "EXTERNAL"
port_range = 443
target = google_compute_target_https_proxy.lb_us_proxy.id
ip_address = google_compute_global_address.ip_address_us.id
}
The recipe was correct. I have added the wrong value for the resource of google_compute_region_network_endpoint_group. Fixed that and it's working now.