Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add defaultCustomErrorResponsePolicy arguments in terraform provider #18200

Open
RubenAtBinx opened this issue May 21, 2024 · 4 comments 路 May be fixed by GoogleCloudPlatform/magic-modules#10787

Comments

@RubenAtBinx
Copy link

RubenAtBinx commented May 21, 2024

Community Note

  • Please vote on this issue by adding a 馃憤 reaction to the original issue to help the community and maintainers prioritize this request.
  • Please do not leave +1 or me too comments, they generate extra noise for issue followers and do not help prioritize the request.
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment.
  • If an issue is assigned to a user, that user is claiming responsibility for the issue.
  • Customers working with a Google Technical Account Manager or Customer Engineer can ask them to reach out internally to expedite investigation and resolution of this issue.

Description

For a while it has been possible to create custom error responses on external application load balancers. The terraform provider for this resource hasn't been updated with this functionality yet.

https://cloud.google.com/load-balancing/docs/https/configure-custom-error-responses

New or Affected Resource(s)

  • google_compute_url_map

Potential Terraform Configuration

resource "google_compute_url_map" "urlmap" {
    name        = "urlmap"
    description = "a description"

    default_service = google_compute_backend_service.home.self_link
  
    default_custom_error_response_policy {
        error_response_rules: {
            match_response_codes: [
                "401"
            ]
            path: "/not-authorized.html"
            override_response_code: 200
        }
        
        error_response_rules: {
            match_response_codes: [
                "404"
            ]
            path: "/not-found.html"
            override_response_code: 200
        }

        error_service: "https://www.googleapis.com/compute/v1/projects/PROJECT_ID/global/backendBuckets/CUSTOM_ERRORS_BUCKET"
    }

    host_rule {
        hosts        = ["mysite.com"]
        path_matcher = "allpaths"
    }

    path_matcher {
        name            = "allpaths"
        default_service = google_compute_backend_service.home.self_link

        default_custom_error_response_policy {
            error_response_rules: {
                match_response_codes: [
                    "401"
                ]
                path: "/not-authorized.html"
                override_response_code: 200
            }

            error_service: "https://www.googleapis.com/compute/v1/projects/PROJECT_ID/global/backendBuckets/CUSTOM_ERRORS_BUCKET"
        }

        path_rule {
            paths   = ["/home"]
            service = google_compute_backend_service.home.self_link
            
            custom_error_response_policy {
                error_response_rules: {
                    match_response_codes: [
                        "401"
                    ]
                    path: "/not-authorized.html"
                    override_response_code: 200
                }

                error_service: "https://www.googleapis.com/compute/v1/projects/PROJECT_ID/global/backendBuckets/CUSTOM_ERRORS_BUCKET"
            }
        }
        
        route_rules {
            priority = 1
            service = google_compute_backend_service.home.self_link
            match_rules {
                prefix_match = "/"
                ignore_case = true
                header_matches {
                    header_name = "abtest"
                    exact_match = "a"
                }
            }
            
            custom_error_response_policy {
                error_response_rules: {
                    match_response_codes: [
                        "401"
                    ]
                    path: "/not-authorized.html"
                    override_response_code: 200
                }

                error_service: "https://www.googleapis.com/compute/v1/projects/PROJECT_ID/global/backendBuckets/CUSTOM_ERRORS_BUCKET"
            }
        }
    }
}

References

No response

b/341993855

@daanheikens
Copy link

Thanks @RubenAtBinx, I will have a look at this one!

@daanheikens
Copy link

The REST API seems to support it: https://cloud.google.com/compute/docs/reference/rest/beta/urlMaps/insert

Happy to do it.

@trodge trodge removed the forward/review In review; remove label to forward label May 21, 2024
@daanheikens
Copy link

daanheikens commented May 24, 2024

Both google_compute_url_map and google_compute_region_url_map support defaultCustomErrorResponsePolicy Will add it to the regional resource as well.

@daanheikens
Copy link

Both google_compute_url_map and google_compute_region_url_map support defaultCustomErrorResponsePolicy Will add it to the regional resource as well.

I am refraining from doing the google_compute_region_url_map to unblock @RubenAtBinx. The errorService field is not supported for regional/internal HTTPS load balancers as stated by the API, however, somehow i can't get it to work with a regional url map in any way. It says the errorService needs a bucket as a target but the backends for buckets are always global, and that one is unexpected for regional url maps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment