cloud-foundation-fabric/blueprints/networking/ilb-next-hop
Dan Farmer 52eb83758f Fix compute-vm:CloudKMS test for provider>=4.54.0
* TF provider >= 4.54.0 now returns `rsa_encrypted_key` for
  `google_compute_disk.disks["attached-disk"]` (see
  hashicorp/terraform-provider-google#4448)
* Add this field to expected model to fix test assertion failure
* Update required TF provider to 4.55.0 (latest) since the assertion
  will now fail with <4.54.0, which do not return `rsa_encrypted_key`
  * Updated the whole repo on advice from @ludoo
2023-02-28 15:10:22 +00:00
..
assets Rename examples folder to blueprints 2022-09-09 16:38:43 +02:00
README.md Update networking bluprints tests 2023-02-25 19:26:11 +01:00
backend.tf.sample Rename examples folder to blueprints 2022-09-09 16:38:43 +02:00
diagram.png Rename examples folder to blueprints 2022-09-09 16:38:43 +02:00
gateways.tf Normalize prefix handling in blueprints (#1003) 2022-11-23 11:09:00 +01:00
main.tf Normalize prefix handling in blueprints (#1003) 2022-11-23 11:09:00 +01:00
outputs.tf Normalize prefix handling in blueprints (#1003) 2022-11-23 11:09:00 +01:00
test_session.png Rename examples folder to blueprints 2022-09-09 16:38:43 +02:00
variables.tf Normalize prefix handling in blueprints (#1003) 2022-11-23 11:09:00 +01:00
versions.tf Fix compute-vm:CloudKMS test for provider>=4.54.0 2023-02-28 15:10:22 +00:00
vms.tf Normalize prefix handling in blueprints (#1003) 2022-11-23 11:09:00 +01:00
vpc-left.tf Normalize prefix handling in blueprints (#1003) 2022-11-23 11:09:00 +01:00
vpc-right.tf Normalize prefix handling in blueprints (#1003) 2022-11-23 11:09:00 +01:00

README.md

Internal Load Balancer as Next Hop

This blueprint bootstraps a minimal infrastructure for testing ILB as next hop, using simple Linux gateway VMS between two VPCs to emulate virtual appliances.

The following diagram shows the resources created by this blueprint

High-level diagram

Two ILBs are configured on the primary and secondary interfaces of gateway VMs with active health checks, but only a single one is used as next hop by default to simplify testing. The second (right-side) VPC has default routes that point to the gateway VMs, to also use the right-side ILB as next hop set the ilb_right_enable variable to true.

Testing

This setup can be used to test and verify new ILB features like forwards all protocols on ILB as next hops and symmetric hashing, using simple curl and ping tests on clients. To make this practical, test VMs on both VPCs have nginx pre-installed and active on port 80.

On the gateways, iftop and tcpdump are installed by default to quickly monitor traffic passing forwarded across VPCs.

Session affinity on the ILB backend services can be changed using gcloud compute backend-services update on each of the ILBs, or by setting the ilb_session_affinity variable to update both ILBs.

Simple /root/start.sh and /root/stop.sh scripts are pre-installed on both gateways to configure iptables so that health check requests are rejected and re-enabled, to quickly simulate removing instances from the ILB backends.

Some scenarios to test:

  • short-lived connections with session affinity set to the default of NONE, then to CLIENT_IP
  • long-lived connections, failing health checks on the active gateway while the connection is active

Useful commands

Basic commands to SSH to VMs and monitor backend health are provided in the Terraform outputs, and they already match input variables so that names, zones, etc. are correct. Other testing commands are provided below, adjust names to match your setup.

Create a large file on a destination VM (eg ilb-test-vm-right-1) to test long-running connections.

dd if=/dev/zero of=/var/www/html/test.txt bs=10M count=100 status=progress

Run curl from a source VM (eg ilb-test-vm-left-1) to send requests to a destination VM artificially slowing traffic.

curl -0 --output /dev/null --limit-rate 10k 10.0.1.3/test.txt

Monitor traffic from a source VM (eg ilb-test-vm-left-1) on the gateways.

iftop -n -F 10.0.0.3/32

Poll summary health status for a backend.

watch '\
  gcloud compute backend-services get-health ilb-test-ilb-right \
    --region europe-west1 \
    --flatten status.healthStatus \
    --format "value(status.healthStatus.ipAddress, status.healthStatus.healthState)" \
'

A sample testing session using tmux:

Test session screenshot

Variables

name description type required default
prefix Prefix used for resource names. string
project_id Existing project id. string
ilb_right_enable Route right to left traffic through ILB. bool false
ilb_session_affinity Session affinity configuration for ILBs. string "CLIENT_IP"
ip_ranges IP CIDR ranges used for VPC subnets. map(string) {…}
project_create Create project instead of using an existing one. bool false
region Region used for resources. string "europe-west1"
zones Zone suffixes used for instances. list(string) ["b", "c"]

Outputs

name description sensitive
addresses IP addresses.
backend_health_left Command-line health status for left ILB backends.
backend_health_right Command-line health status for right ILB backends.
ssh_gw Command-line login to gateway VMs.
ssh_vm_left Command-line login to left VMs.
ssh_vm_right Command-line login to right VMs.

Test

module "test" {
  source         = "./fabric/blueprints/networking/ilb-next-hop"
  prefix         = "test"
  project_create = true
  project_id     = "project-1"
}
# tftest modules=18 resources=42