terraform-google-lb-http icon indicating copy to clipboard operation
terraform-google-lb-http copied to clipboard

URL Map functionality

Open zdunning13 opened this issue 2 years ago • 4 comments

TL;DR

Additional functionality to create a URL map with multiple host and path rules

Terraform Resources

google_compute_url_map

Detailed design

From what I can tell, this modules doesn't support the creation of a custom URL map.

We have a use case where we would like to create a URL map that has multiple host rules (patch-matchers) that point to different backend services. We would like to use this module and our custom made URL map.

We are currently running into a chicken/egg situation. The current module will create all of the backend services/buckets, but not a dynamic URL map with host rules to point to these backend. The URL map obviously needs to exist for this module to point to it

The below code will create a dynamic URL map with multiple host rules, but it requires the backend services to exist, which we would prefer to create with the existing module.


resource "google_compute_url_map" "lb_url_map" {
    project = var.project
    name = var.name
    default_service = var.default_service

    dynamic "host_rule" {
        for_each = var.hosts
        content {
            hosts = host_rule.value["hosts"]
            path_matcher = host_rule.value["path_matcher"]
        }
    }

    dynamic "path_matcher" {
        for_each = var.hosts
        content {
            name = path_matcher.value["path_matcher"]
            default_service = path_matcher.value["default_service"]
        }
    }
}

Additional information

No response

zdunning13 avatar May 05 '22 18:05 zdunning13

Yeah, realised the same issue! After making all the changes and realizing this module does not support one load balancer pointing to multiple backend services, in the URL_MAP, it requires a default backend service, however, the backend services need to be created in the module while the module needs to have the URL_MAP.

ivanzhujunwei avatar Jun 15 '22 13:06 ivanzhujunwei

Hi actually this is not an issue, I find a different way to reference the backend service in the URL_MAP, you could reference the backend services like this way: default_service = module.lb-https.backend_services["XXX"].self_link Then Terraform will figure out the sequences of creating different resources.

ivanzhujunwei avatar Jun 16 '22 04:06 ivanzhujunwei

Thanks for pointing this out @ivanzhujunwei - It works for the initial apply but whenever I make any change to the url_map Terraform fails at apply with the following error:

google_compute_url_map.urlmap: Destroying... [id=projects/test-07cf1591/global/urlMaps/urlmap]

Error: Error when reading or editing UrlMap: googleapi: Error 400: The url_map resource 'projects/test-07cf1591/global/urlMaps/urlmap' is already being used by 'projects/test-07cf1591/global/targetHttpsProxies/test-global-lb-https-proxy', resourceInUseByAnotherResource

Looks to me like it's trying to delete the url_map when it should be either updating in-place or creating a new and switching to this before deleting the original.

My apologies in advance if this has nothing to do with lb-http as I'm new to Terraform.

MrTin avatar Jul 18 '22 22:07 MrTin

Hi @MrTin based on the error message you provided, it seems the URL MAP is being used by a different resource (targetHttpsProxies/test-global-lb-https-proxy) that why you cannot delete it. what I know is for some specific resource, terraform does not automatically update all the relevant resource, but I am not across all your changes, you might want to try to unlink the dependency between those resources, or trying to destroy targetHttpsProxies/test-global-lb-https-proxy first. Cheers!

ivanzhujunwei avatar Jul 20 '22 07:07 ivanzhujunwei

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days

github-actions[bot] avatar Sep 18 '22 23:09 github-actions[bot]