hashicorp / terraform-provider-google

Terraform Provider for Google Cloud Platform
https://registry.terraform.io/providers/hashicorp/google/latest/docs
Mozilla Public License 2.0
2.32k stars 1.72k forks source link

Add support for advanced routing rules for External HTTP(s) Load Balancers #6634

Closed Hmerac closed 4 years ago

Hmerac commented 4 years ago

Community Note

Description

We tried to use header-based routing for one of our External HTTP(s) Load Balancers by header_matches, but received Advanced routing rules are not supported for scheme EXTERNAL, invalid error.

As Terraform documentation for compute_url_map states, advanced routing such as header-based routing is not possible for External HTTP(s) Load Balancers. Yet, on GCP documentation, it's possible with gcloud utility but not via Console. You can see it in below documentations:

New or Affected Resource(s)

edwardmedia commented 4 years ago

@Hmerac Can you see if below code works for you?

resource "google_compute_url_map" "urlmap" {
name        = "urlmap"
  description = "header-based routing example"
  default_service = google_compute_backend_service.default.id
  host_rule {
    hosts = ["*"]
    path_matcher = "allpaths"
  }
  path_matcher {
    name = "allpaths"
    default_service = google_compute_backend_service.default.id
    route_rules {
      priority = 1
      service = google_compute_backend_service.service-a.id
      match_rules {
        prefix_match = "/"
        ignore_case = true
        header_matches {
          header_name = "abtest"
          exact_match = "a"
        }
      }
    }
    route_rules {
      priority = 2
      service = google_compute_backend_service.service-b.id
      match_rules {
        ignore_case = true
        prefix_match = "/"
        header_matches {
          header_name = "abtest"
          exact_match = "b"
        }
      }
    }
  }
}
edwardmedia commented 4 years ago

@Hmerac examples are added https://github.com/terraform-providers/terraform-provider-google/issues/6340 Please let me know if that addresses your request.

Hmerac commented 4 years ago

@Hmerac Can you see if below code works for you?

resource "google_compute_url_map" "urlmap" {
name        = "urlmap"
  description = "header-based routing example"
  default_service = google_compute_backend_service.default.id
  host_rule {
    hosts = ["*"]
    path_matcher = "allpaths"
  }
  path_matcher {
    name = "allpaths"
    default_service = google_compute_backend_service.default.id
    route_rules {
      priority = 1
      service = google_compute_backend_service.service-a.id
      match_rules {
        prefix_match = "/"
        ignore_case = true
        header_matches {
          header_name = "abtest"
          exact_match = "a"
        }
      }
    }
    route_rules {
      priority = 2
      service = google_compute_backend_service.service-b.id
      match_rules {
        ignore_case = true
        prefix_match = "/"
        header_matches {
          header_name = "abtest"
          exact_match = "b"
        }
      }
    }
  }
}

I actually tried to apply the same logic with GCP provider version of v3.25.0, that's how I got the error. I should've pointed that out in the description, sorry.

Did this work for you?

edwardmedia commented 4 years ago

@Hmerac what error do you receive if above code does not work for you? Can you share your debug log?

Hmerac commented 4 years ago

@edwardmedia I cannot reproduce the same case now because we've proceeded with Istio to do the header-based routing. But, as far as I remember the only error we received was:

Advanced routing rules are not supported for scheme EXTERNAL, invalid

Which I believe is quite understandable, looking at the terraform docs for google_compute_url_map for route_rules: https://www.terraform.io/docs/providers/google/r/compute_url_map.html

Screenshot 2020-06-26 at 14 36 53
edwardmedia commented 4 years ago

@Hmerac routeRules should work for External load balancers now. The doc is out of date, and we are going to update it. I am closing this issue. Please feel free to reopen it if you see the error Advanced routing rules are not supported for scheme EXTERNAL, invalid again. Thanks

ghost commented 4 years ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 hashibot-feedback@hashicorp.com. Thanks!