HTTPS Load Balancer add host path rules using gcloud

Hi All,

I have a requirement to create / updated the HTTPS load balancer dynamically with different host path rules (Serverless NEG as backends)

I have created a url-map for the 1st time using below command

gcloud compute url-maps add-path-matcher test-lb --path-matcher-name=test-path-match --default-service=my-neg-be --path-rules=“/path_1=my-neg-be,/path_1/*=my-neg-be” --new-hosts=test.mydomain.com

Now I wanted to add subsequent path rules dynamically using gcloud during a deployment. So have I am unable to find a gcloud command qcloud command which can be used to add subsequent path rules.

Just want to check if anyone have thoughts around this. thank you.

Regards,

Pradeep

Hi @dumpalap ,

I’m not quite sure what you meant by adding path rules “dynamically”.

But if the intent is to edit the URL map to add or change the path rules, you might find this command useful:

gcloud compute url-maps edit <map>

The command opens the map in a text editor. Make the necessary changes and save them.

Doc: https://cloud.google.com/sdk/gcloud/reference/compute/url-maps/edit

The easiest way is to run this command

gcloud compute url-maps list --filter=“BACKEND_SERVICE_NAME”

Considering the related documentation [1] as your objective.

When you mention load balancer, I assume that you are referring to serverless NEG [2] and that you have configured a group of Cloud Run services behind a load balancer.

[1]: https://cloud.google.com/load-balancing/docs/https/setting-up-global-traffic-mgmt#rewrite_the_requested_url

[2] : https://cloud.google.com/load-balancing/docs/negs/serverless-neg-concepts

Hi @kumards ,

Thanks for the response. I have gone thru the command which you have given. This opens a editor to add the rules. My scenario will run in a release pipeline and I can not take an approach of interactive editor.

One option I am thinking is edit the yaml content in command line and import it. But want to check if there is any better way.

Regards,

Pradeep

Thanks for clarifying the requirement, Pradeep! I agree that the interactive approach offered by gcloud compute url-maps edit won’t be useful for automated/programmatic updates. I wonder whether you could use a client library (examples: https://cloud.google.com/compute/docs/reference/rest/v1/urlMaps/update#examples)

Hi @kumards ,

Thanks for providing the details. I am trying with client library and it looks like we can achieve this with some tweaking. But I am keep getting the error in update action.

Action:

update_url_map_request = service.urlMaps().update(project=project, urlMap=url_map, body=‘urlMapJsonData.json’)
update_url_map_request = update_url_map_request.execute()

Error:

“Required field ‘resource.fingerprint’ not specified”. Details: “[{‘message’: “Required field ‘resource.fingerprint’ not specified”, ‘domain’: ‘global’, ‘reason’: ‘required’}]”>

My JSON request is having fingerprint in it. please see the below screen print.

Please let me know if you have any clue ?

Regards,

Pradeep

Hi @kumards , please ignore my earlier message.