Serverless Load Balancing with Terraform: The Hard Way

Serverless Load Balancing with Terraform: The Hard Way

Terraform module for serverless load balancing With the new optimized Terraform load balancing module, can now set up load balancing for serverless applications. Serverless load balancing with Terraform: The hard way.

Earlier this year, we announced  Cloud Load Balancer support for Cloud Run. You might wonder, aren't Cloud Run services already load-balanced? Yes, each * endpoint load balances traffic between an autoscaling set of containers. However, with the Cloud Balancing integration for serverless platforms, you can now fine tune lower levels of your networking stack. In this article, we will explain the use cases for this type of set up and build an HTTPS load balancer from ground up for Cloud Run using  Terraform.

Why use a Load Balancer for Cloud Run?

Every Cloud Run service comes with a load-balanced * endpoint that’s secured with HTTPS. Furthermore, Cloud Run also lets you  map your custom domains to your services. However, if you want to customize other details about how your load balancing works, you need to provision a  Cloud HTTP load balancer yourself.

Here are a few reasons to run your Cloud Run service behind a Cloud Load Balancer:

  • Serving static assets with CDN since Cloud CDN integrates with Cloud Load Balancing
  • Serving traffic from multiple regions since Cloud Run is a regional service but you can provision a load balancer with a global anycast IP and route users to the closest available region.
  • Serve content from mixed backends, for example your /static path can be served from a storage bucket, /api can go to a Kubernetes cluster.
  • Bring your own TLS certificates, such as wildcard certificates you might have purchased.
  • Customize networking settings, such as TLS versions and ciphers supported.
  • Authenticating and enforcing authorization for specific users or groups with  Cloud IAP (this does not work yet with Cloud Run, however, stay tuned)
  • Configure WAF or DDoS protection with  Cloud Armor.

The list goes on, Cloud HTTP Load Balancing has quite a lot of  features.

Why use Terraform for this?

The short answer is that a Cloud HTTP Load Balancer consists of  many networking resources that you need to create and connect to each other. There’s no single "load balancer" object in GCP APIs.

To understand the upcoming task, let's take a look at the resources involved:

  • global IP address for your load balancer
  • Google-managed  SSL certificate (or bring your own)
  • forwarding rules to associate IP address with backends
  • target HTTPS proxy to terminate your HTTPS traffic
  • target HTTP proxy to receive HTTP traffic and redirect to HTTPS
  • URL maps to specify routing rules for URL path patterns.
  • backend service to keep track of eligible backends
  • network endpoint group allowing you to register serverless apps as backends.

developers & practitioners serverless

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

How long does it take to develop/build an app?

This article covers A-Z about the mobile and web app development process and answers your question on how long does it take to develop/build an app.

Developer Career Path: To Become a Team Lead or Stay a Developer?

For a developer, becoming a team leader can be a trap or open up opportunities for creating software. Two years ago, when I was a developer, ... by Oleg Sklyarov, Fullstack Developer at Skyeng company

Offshore Software Development - Best Practices

To make the most out of the benefits of offshore software development, you should understand the crucial factors that affect offshore development.

Hire Magento Developer | Hire dedicated Magento Developer

Hire Certified Magento Developers from USA or India to get stunnig and visual ecommerce stores which creates a superior shopping experiences with focus on conversions.

Mobile Wallet Development, eWallet App Development, Digital Wallet App Development

Get the most of what the digital world has to offer with our innovative range of Digital wallet app development services. Enable your customers to store, send, and receive funds with ease and security. A customizable offering that is highly efficient and scalable.