cloud-foundation-fabric/modules/net-ilb
Ludovico Magnocavallo 4a40497ce6
Update README.md
2020-06-05 09:51:36 +02:00
..
README.md Update README.md 2020-06-05 09:51:36 +02:00
main.tf Fix health checks in net-ilb and compute-mig modules (#69) 2020-05-07 07:37:15 +02:00
outputs.tf Fix health checks in net-ilb and compute-mig modules (#69) 2020-05-07 07:37:15 +02:00
variables.tf MIG and ILB modules (#61) 2020-04-30 17:08:18 +02:00

README.md

Internal Load Balancer Module

This module allows managing a GCE Internal Load Balancer and integrates the forwarding rule, regional backend, and optional health check resources. It's designed to be a simple match for the compute-vm module, which can be used to manage instance templates and instance groups.

TODO

  • do not create health check resource if var.health_check is not null (workaround is to set var.health_check_config to null
  • add a variable for setting address purpose to SHARED_LOADBALANCER_VIP and an output for the address once the provider support has been implemented

Issues

TODO(ludoo): check if this is still the case after splitting out MIG from compute-vm

There are some corner cases (eg when switching the instance template from internal service account to an externally managed one) where Terraform raises a cycle error on apply. In these situations, run successive applies targeting resources used in the template first then the template itself, and the cycle should be fixed.

One other issue is a Provider produced inconsistent final plan error which is sometimes raised when switching template version. This seems to be related to this open provider issue, but it's relatively harmless since the resource is updated, and subsequent applies raise no errors.

Example

This example spins up a simple HTTP server and combines four modules:

  • nginx from the cloud-config-container collection, to manage instance configuration
  • compute-vm to manage the instance template and unmanaged instance group
  • this module to create an Internal Load Balancer in front of the managed instance group

Note that the example uses the GCE default service account. You might want to create an ad-hoc service account by combining the iam-service-accounts module, or by having the GCE VM module create one for you. In both cases, remember to set at least logging write permissions for the service account, or the container on the instances won't be able to start.

module "cos-nginx" {
  source = "./modules/cloud-config-container/nginx"
}

module "instance-group" {
  source     = "./modules/compute-vm"
  project_id = "my-project"
  region     = "europe-west1"
  zone       = "europe-west1-b"
  name       = "ilb-test"
  network_interfaces = [{
    network    = local.network_self_link,
    subnetwork = local.subnetwork_self_link,
    nat        = false,
    addresses  = null
  }]
  boot_disk = {
    image = "projects/cos-cloud/global/images/family/cos-stable"
    type  = "pd-ssd"
    size  = 10
  }
  tags                   = ["http-server", "ssh"]
  metadata = {
    user-data = module.cos-nginx.cloud_config
  }
  group = {}
}

module "ilb" {
  source        = "./modules/net-ilb"
  project_id    = "my-project"
  region        = "europe-west1"
  name          = "ilb-test"
  service_label = "ilb-test"
  network       = local.network_self_link
  subnetwork    = local.subnetwork_self_link
  ports         = [80]
  backends = [{
    failover       = false
    group          = module.instance-group.group.self_link
    balancing_mode = "CONNECTION"
  }]
  health_check_config = {
    type = "http", check = { port = 80 }, config = {}, logging = true
  }
}

Variables

name description type required default
backends Load balancer backends, balancing mode is one of 'CONNECTION' or 'UTILIZATION'. list(object({...}))
name Name used for all resources. string
network Network used for resources. string
project_id Project id where resources will be created. string
region GCP region. string
subnetwork Subnetwork used for the forwarding rule. string
address Optional IP address used for the forwarding rule. string null
backend_config Optional backend configuration. object({...}) null
failover_config Optional failover configuration. object({...}) null
global_access Global access, defaults to false if not set. bool null
health_check Name of existing health check to use, disables auto-created health check. string null
health_check_config Configuration of the auto-created helth check. object({...}) ...
labels Labels set on resources. map(string) {}
log_sample_rate Set a value between 0 and 1 to enable logging for resources, and set the sampling rate for backend logging. number null
ports Comma-separated ports, leave null to use all ports. list(string) null
protocol IP protocol used, defaults to TCP. string TCP
service_label Optional prefix of the fully qualified forwarding rule name. string null

Outputs

name description sensitive
backend Backend resource.
backend_id Backend id.
backend_self_link Backend self link.
forwarding_rule Forwarding rule resource.
forwarding_rule_address Forwarding rule address.
forwarding_rule_id Forwarding rule id.
forwarding_rule_self_link Forwarding rule self link.
health_check Auto-created health-check resource.
health_check_self_id Auto-created health-check self id.
health_check_self_link Auto-created health-check self link.