Configure multiple regions
Stay organized with collections
Save and categorize content based on your preferences.
Set a Cloud Run service to be available in multiple regions
Code sample
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],[],[],[],null,["# Configure multiple regions\n\nSet a Cloud Run service to be available in multiple regions\n\nCode sample\n-----------\n\n### Terraform\n\n\nTo learn how to apply or remove a Terraform configuration, see\n[Basic Terraform commands](/docs/terraform/basic-commands).\n\n\nFor more information, see the\n[Terraform provider reference documentation](https://registry.terraform.io/providers/hashicorp/google/latest/docs).\n\n resource \"google_project_service\" \"compute_api\" {\n provider = google-beta\n service = \"compute.googleapis.com\"\n disable_dependent_services = false\n disable_on_destroy = false\n }\n\n resource \"google_project_service\" \"run_api\" {\n provider = google-beta\n service = \"run.googleapis.com\"\n disable_dependent_services = false\n disable_on_destroy = false\n }\n\n resource \"google_compute_global_address\" \"lb_default\" {\n provider = google-beta\n name = \"myservice-service-ip\"\n\n # Use an explicit depends_on clause to wait until API is enabled\n depends_on = [\n google_project_service.compute_api\n ]\n }\n\n resource \"google_compute_backend_service\" \"lb_default\" {\n provider = google-beta\n name = \"myservice-backend\"\n load_balancing_scheme = \"EXTERNAL_MANAGED\"\n\n backend {\n group = google_compute_region_network_endpoint_group.lb_default[0].id\n }\n\n backend {\n group = google_compute_region_network_endpoint_group.lb_default[1].id\n }\n\n # Use an explicit depends_on clause to wait until API is enabled\n depends_on = [\n google_project_service.compute_api,\n ]\n }\n\n resource \"google_compute_url_map\" \"lb_default\" {\n provider = google-beta\n name = \"myservice-lb-urlmap\"\n default_service = google_compute_backend_service.lb_default.id\n\n path_matcher {\n name = \"allpaths\"\n default_service = google_compute_backend_service.lb_default.id\n route_rules {\n priority = 1\n url_redirect {\n https_redirect = true\n redirect_response_code = \"MOVED_PERMANENTLY_DEFAULT\"\n }\n }\n }\n }\n\n resource \"google_compute_managed_ssl_certificate\" \"lb_default\" {\n provider = google-beta\n name = \"myservice-ssl-cert\"\n\n managed {\n domains = [\"example.com\"]\n }\n }\n resource \"google_compute_target_https_proxy\" \"lb_default\" {\n provider = google-beta\n name = \"myservice-https-proxy\"\n url_map = google_compute_url_map.lb_default.id\n ssl_certificates = [\n google_compute_managed_ssl_certificate.lb_default.name\n ]\n depends_on = [\n google_compute_managed_ssl_certificate.lb_default\n ]\n }\n\n resource \"google_compute_global_forwarding_rule\" \"lb_default\" {\n provider = google-beta\n name = \"myservice-lb-fr\"\n load_balancing_scheme = \"EXTERNAL_MANAGED\"\n target = google_compute_target_https_proxy.lb_default.id\n ip_address = google_compute_global_address.lb_default.id\n port_range = \"443\"\n depends_on = [google_compute_target_https_proxy.lb_default]\n }\n\n resource \"google_compute_region_network_endpoint_group\" \"lb_default\" {\n provider = google-beta\n count = length(local.run_regions)\n name = \"myservice-neg\"\n network_endpoint_type = \"SERVERLESS\"\n region = local.run_regions[count.index]\n cloud_run {\n service = google_cloud_run_v2_service.run_default[count.index].name\n }\n }\n\n output \"load_balancer_ip_addr\" {\n value = google_compute_global_address.lb_default.address\n }\n\n resource \"google_cloud_run_v2_service\" \"run_default\" {\n provider = google-beta\n count = length(local.run_regions)\n name = \"myservice-run-app-${local.run_regions[count.index]}\"\n location = local.run_regions[count.index]\n\n deletion_protection = false # set to \"true\" in production\n\n template {\n containers {\n image = \"us-docker.pkg.dev/cloudrun/container/hello\"\n }\n }\n\n # Use an explicit depends_on clause to wait until API is enabled\n depends_on = [\n google_project_service.run_api\n ]\n }\n\n resource \"google_cloud_run_service_iam_member\" \"run_allow_unauthenticated\" {\n provider = google-beta\n count = length(local.run_regions)\n location = google_cloud_run_v2_service.run_default[count.index].location\n service = google_cloud_run_v2_service.run_default[count.index].name\n role = \"roles/run.invoker\"\n member = \"allUsers\"\n }\n\n resource \"google_compute_url_map\" \"https_default\" {\n provider = google-beta\n name = \"myservice-https-urlmap\"\n\n default_url_redirect {\n redirect_response_code = \"MOVED_PERMANENTLY_DEFAULT\"\n https_redirect = true\n strip_query = false\n }\n }\n\n resource \"google_compute_target_http_proxy\" \"https_default\" {\n provider = google-beta\n name = \"myservice-http-proxy\"\n url_map = google_compute_url_map.https_default.id\n\n depends_on = [\n google_compute_url_map.https_default\n ]\n }\n\n resource \"google_compute_global_forwarding_rule\" \"https_default\" {\n provider = google-beta\n name = \"myservice-https-fr\"\n target = google_compute_target_http_proxy.https_default.id\n ip_address = google_compute_global_address.lb_default.id\n port_range = \"80\"\n depends_on = [google_compute_target_http_proxy.https_default]\n }\n\nWhat's next\n-----------\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=cloudrun)."]]