Skip to content

Latest commit

 

History

History

mig-nat-http-lb

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Global HTTP Example to GCE instances with NAT Gateway

button

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

architecture diagram

Change to the example directory

[[ `basename $PWD` != mig-nat-http-lb ]] && cd examples/mig-nat-http-lb

Install Terraform

  1. Install Terraform if it is not already installed (visit terraform.io for other distributions):

Set up the environment

  1. Set the project, replace YOUR_PROJECT with your project ID:
PROJECT=YOUR_PROJECT
gcloud config set project ${PROJECT}
  1. Configure the environment for Terraform:
[[ $CLOUD_SHELL ]] || gcloud auth application-default login
export GOOGLE_PROJECT=$(gcloud config get-value project)

Run Terraform

terraform init
terraform apply

Testing

  1. 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.

Cleanup

  1. Remove all resources created by terraform:
terraform destroy

Inputs

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

Outputs

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"