http-redirectgoogle-cloud-platformload-balancinggcloudgoogle-cloud-url-maps

GCP - How do you create a URL Redirect path rule with gcloud url-maps?


I want to create a GCP Load Balancer path redirect rule programatically using the gcloud tool.

As a test, I created one manually through the GCP Console web interface.

For my manually created rule, gcloud compute url-maps describe my-url-map returns something that looks like:

creationTimestamp: '2021-02-23T20:26:04.825-08:00'
defaultService: https://www.googleapis.com/compute/v1/projects/my-project/global/backendServices/my-backend-service
fingerprint: abcdefg=
hostRules:
- hosts:
  - blah.my-site.com
  pathMatcher: path-matcher-1
id: '12345678'
kind: compute#urlMap
name: my-url-map
pathMatchers:
- defaultService: https://www.googleapis.com/compute/v1/projects/my-project/global/backendServices/my-backend-service
  name: path-matcher-1
  pathRules:
  - paths:
    - /my-redirect-to-root
    urlRedirect:
      httpsRedirect: false
      pathRedirect: /
      redirectResponseCode: MOVED_PERMANENTLY_DEFAULT
      stripQuery: false
selfLink: https://www.googleapis.com/compute/v1/projects/my-project/global/urlMaps/my-url-map

What I would like to do is to recreate the urlRedirect rule above (redirecting from /my-redirect-to-root to /), but using the gcloud tool.

Looking through the gcloud docs I can't seem to find anything referring to redirects. Is it that this is not possible to do via the gcloud tool? and if not, is there any other solution for creating these redirect rules programatically?

I'm basically trying to get around another GCP issue to do with GCS URLs for static websites by using Load Balancer redirects for each folder in our static site (~400 folders).


Solution

  • Currently Cloud SDK does not support creating url maps with redirects.
    If you think that functionality should be available, you can create a Feature Request at Public Issue Tracker to have this option added in future.

    For now, you can use API which allows creating url maps with redirects.