This example creates an HTTPS load balancer to forward traffic to a custom URL map. The URL map sends traffic to the region closest to you with static assets being served from a Cloud Storage bucket. The TLS key and certificate is generated by Terraform using the TLS provider.
Figure 1. diagram of Google Cloud resources
[[ `basename $PWD` != multi-backend-multi-mig-bucket-https-lb ]] && cd examples/multi-backend-multi-mig-bucket-https-lb/
- Install Terraform if it is not already installed (visit terraform.io for other distributions):
- Set the project, replace
YOUR_PROJECT
with your project ID:
PROJECT=YOUR_PROJECT
gcloud config set project ${PROJECT}
- Configure the environment for Terraform:
[[ $CLOUD_SHELL ]] || gcloud auth application-default login
export GOOGLE_PROJECT=$(gcloud config get-value project)
terraform init
terraform apply
- Open URL of load balancer in browser:
echo http://$(terraform output load-balancer-ip)| sed 's/"//g'
You should see the GCP logo and instance details from the group closest to your geographical region.
- Open URL to route mapped to us-west1 instance group:
echo http://$(terraform output load-balancer-ip)/group1/ | sed 's/"//g'
You should see the GCP logo and instance details from the group in us-west1.
- Open URL to route mapped to us-central1 instance group:
echo http://$(terraform output load-balancer-ip)/group2/ | sed 's/"//g'
You should see the GCP logo and instance details from the group in us-central1.
- Open URL to route mapped to us-east1 instance group:
echo http://$(terraform output load-balancer-ip)/group3/ | sed 's/"//g'
You should see the GCP logo and instance details from the group in us-east1.
- Remove all resources created by terraform:
terraform destroy
Name | Description | Type | Default | Required |
---|---|---|---|---|
group1_region | n/a | string |
"us-west1" |
no |
group2_region | n/a | string |
"us-central1" |
no |
group3_region | n/a | string |
"us-east1" |
no |
network_name | n/a | string |
"ml-bk-ml-mig-bkt-s-lb" |
no |
project | n/a | string |
n/a | yes |
Name | Description |
---|---|
asset-url | n/a |
asset-url-ipv6 | The asset url over IPv6 address of the load-balancer, if enabled; else "undefined" |
group1_region | n/a |
group2_region | n/a |
group3_region | n/a |
load-balancer-ip | n/a |
load-balancer-ipv6 | The IPv6 address of the load-balancer, if enabled; else "undefined" |