This example creates a global HTTP forwarding rule to an instance group without external IPs. The instances access the internet via a NAT gateway.
Figure 1. diagram of Google Cloud resources
[[ `basename $PWD` != mig-nat-http-lb ]] && cd examples/mig-nat-http-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 the URL of the load balancer in your browser:
echo http://$(terraform output load-balancer-ip)| sed 's/"//g'
You should see the instance details from group1
.
- Remove all resources created by terraform:
terraform destroy
Name | Description | Type | Default | Required |
---|---|---|---|---|
network_name | n/a | string |
"tf-lb-http-mig-nat" |
no |
project | n/a | string |
n/a | yes |
region | n/a | string |
"us-west1" |
no |
Name | Description |
---|---|
backend_services | n/a |
load-balancer-ip | n/a |
load-balancer-ipv6 | The IPv6 address of the load-balancer, if enabled; else "undefined" |