DEV Community

Chris ter Beke
Chris ter Beke

Posted on • Originally published at xebia.com on

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

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" {
    ...
}

Enter fullscreen mode Exit fullscreen mode

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"
}

Enter fullscreen mode Exit fullscreen mode

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.

The post Creating a non-classic Google Cloud Global Load Balancer with Terraform appeared first on Xebia.

Top comments (0)