Skip to content

Latest commit

 

History

History
129 lines (102 loc) · 5.47 KB

README.md

File metadata and controls

129 lines (102 loc) · 5.47 KB

Google Load Balancer Terraform module

Terraform module which creates Load Balancer resources on GCP.

User Stories for this module

  • AASRE I can create one load balancer
  • AASRE I can specify multiple backend services
  • AASRE I can specify certificates to be used
  • AASRE I can handle granular routing on LB
  • AASRE I can specify the SSL Policy
  • AASRE I can specify the security policy
  • AASRE I can activate CDN on each backend service

Usage

module "my_lb" {
  source = "git@github.com:padok-team/terraform-google-lb.git?ref=v1.0.1"

  name = "my-lb"
  buckets_backends = {
    frontend = {
      hosts = ["example-bucket.playground.padok.cloud"]
      path_rules = [
        {
          paths = ["/*"]
        }
      ]
      bucket_name = "example-bucket"
      cdn_policy  = "react"
    }
  }
  service_backends = {
    backend = {
      hosts = ["echo.playground.padok.cloud"]
      path_rules = [
        {
          paths = ["/*"]
        }
      ]
      groups = [google_compute_region_network_endpoint_group.backend.id]
    }
  }
  ssl_certificates    = [data.google_compute_ssl_certificate.playground.self_link]
  custom_cdn_policies = {}
}

Embedded CDN Policies

Currently, this module only supports the following CDN policy. You can reference it directly in the module usage:

  • react
react = {
  cache_mode       = "USE_ORIGIN_HEADERS"
  negative_caching = true
  negative_caching_policy = {
    "404" = {
      code = "404"
      ttl  = "1"
    },
  }
}

Don't hesitate to add other CDN policies!

Alternatively, you can set custom CDN Policies as explained in the Terraform documentation.

⚠️ The structure of the resource might change, we're based on google provider 3.90 version.

Usage examples

Modules

No modules.

Inputs

Name Description Type Default Required
buckets_backends A map of buckets to add as the load balancer backends.
map(object({
hosts = list(string)
bucket_name = string
cdn_policy = optional(string)
path_rules = list(object({
paths = list(string)
}))
security_policy = optional(string)
}))
n/a yes
name The load balancer name. string n/a yes
project_id The project to deploy the ressources to. string n/a yes
service_backends A map of services to add as the load balancer backends.
map(object({
hosts = list(string)
groups = list(string)
path_rules = list(object({
paths = list(string)
}))
security_policy = optional(string)
}))
n/a yes
custom_cdn_policies A map of additional custom CDN policies you can add to the load balancer.
map(object({
cache_mode = optional(string, null)
client_ttl = optional(number, null)
default_ttl = optional(number, null)
max_ttl = optional(number, null)
negative_caching = optional(bool, null)
negative_caching_policy = optional(map(object({
code = optional(number, null)
ttl = optional(number, null)
})), null)
serve_while_stale = optional(number, null)
signed_url_cache_max_age_sec = optional(number, null)
}))
{} no
ip_address The load balancer's IP address. string "" no
ssl_certificates A list of SSL certificates for the load balancer. list(string) [] no

Outputs

Name Description
ip_address The IP address of the load balancer.

License

License

See LICENSE for full details.

Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

  https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.