Blog

Creating a non-classic Google Cloud Global Load Balancer with Terraform

16 Sep, 2022
Xebia Background Header Wave

The Google Cloud Terraform Provider has resources to configure a Global External HTTP(S) Load Balancer.
By default however this creates a classic load balancer, not a new one.
For new features like traffic management you cannot use the classic load balancer, so you definitely want to use the new one.

The Google and Terraform documentation is not clear about how to do this properly.
The name classic does not even appear once on the documentation pages for the relevant resources.

A typical Global Load Balancing stack looks like this:

resource "google_compute_global_address" "default" {
    ...
}

resource "google_compute_backend_service" "default" {
    ...
}

resource "google_compute_url_map" "default" {
    ...
}

resource "google_compute_target_http_proxy" "default" {
    ...
}

resource "google_compute_global_forwarding_rule" "default" {
    ...
}

In this stack, google_compute_backend_service is the load balancing back-end, and google_compute_global_forwarding_rule is the front-end.

In order to use a new load balancer, both the back-end and front-end need to have their load_balancing_scheme configured:

resource "google_compute_backend_service" "default" {
    ...
    load_balancing_scheme = "EXTERNAL_MANAGED"
}

resource "google_compute_global_forwarding_rule" "default" {
    ...
    load_balancing_scheme = "EXTERNAL_MANAGED"
}

Conclusion

Now you know how to create a non-classic Global Load Balancer in Google Cloud using Terraform.
The configuration is simple, but hard to find based on the available documentation.

Chris ter Beke
Chris ter Beke has been using Google Cloud Platform for over 8 years. He has built multiple SaaS platforms using technologies like Terraform, Kubernetes, Python, and automated CI/CD pipelines.
Questions?

Get in touch with us to learn more about the subject and related solutions

Explore related posts