0

Below is my terraform script. I have set up the necessary forwarding rules and target http proxies. Also the backend services exist. I am able to access all paths under /images/*, however, I can’t access the paths under /videos/*. From the script, the dafault backend service is backend-lb-prod which is the backend service where the path /images/* exists. I switched the default backend service to backend-lb, I could now access /videos/* but not /images/*.

resource "google_compute_url_map" "url-map-be" {
  name            = "${var.platform_name}-url-map-be-prod"
  default_service = "${google_compute_backend_service.backend-lb-prod.self_link}"

  host_rule {
    hosts        = ["${var.backend_address_name}"]
    path_matcher = "allpaths"
  }

  path_matcher {
    name            = "allpaths"
    default_service = "${google_compute_backend_service.backend-lb-prod.self_link}"

    path_rule {
      paths   = [“/images"]
      service = "${google_compute_backend_service.backend-lb-prod.self_link}"
    }  

    path_rule {
      paths   = [“/images/*"]
      service = "${google_compute_backend_service.backend-lb-prod.self_link}"
    } 

    path_rule {
      paths   = ["/videos"]
      service = "${google_compute_backend_service.backend-lb.self_link}"
    }  

    path_rule {
      paths   = ["/videos/*"]
      service = "${google_compute_backend_service.backend-lb.self_link}"
    }

  }
}

When I run the tests for the url map on the google console, this is the error I get

Invalid value for field 'resource': ''. Test failure: Expect URL ‘*.*.*.*/videos/go' 
to map to service ‘***93-BACKEND_SERVICE-**-backend-lb', but actually mapped to 
'***93-BACKEND_SERVICE-**-backend-lb-prod’.

This is how google_compute_url_map in the terraform documentation is illustrated. What am I missing in this case.

update

I have included the /videos and /images paths and the error above is gone. However, from the logs of the application, the traffic is still sent through the default backend service.

philo
  • 121
  • 1
  • 9

1 Answers1

1

Hope this helps any other person. Under the host_rule the hosts was initially an IP address. I also had it changed to a domain name but it still sent all traffic to the default backend service. I changed it to * and it now works as expected. Also to be noted, the paths that are not of the default backend service take a few minutes before they can be accessed.

host_rule {
  hosts        = ["*"]
  path_matcher = "allpaths"
}
philo
  • 121
  • 1
  • 9