terraform-provider-google/examples/two-tier
2018-10-02 16:07:28 -07:00
..
scripts Address #5912: google-two-tier example incomplete 2016-03-29 22:18:54 +01:00
.gitignore google: Add example of two-tier app 2015-08-09 15:33:03 +01:00
main.tf 1.0.0 Deprecations, pt 2 2017-09-29 16:04:52 -07:00
output.tf Deprecate assigned_nat_ip in compute_instance family (#2155) 2018-10-02 16:07:28 -07:00
README.md Address #5912: google-two-tier example incomplete 2016-03-29 22:18:54 +01:00
terraform.tfvars.example Fix Google Cloud Two-Tier Example (#7009) 2016-06-05 00:48:54 +01:00
variables.tf Fmt all the config files 2016-09-22 11:49:09 +00:00

Basic Two-Tier Architecture in Google Cloud

This provides a template for running a simple two-tier architecture on Google Cloud. The premise is that you have stateless app servers running behind a load balancer serving traffic.

To simplify the example, this intentionally ignores deploying and getting your application onto the servers. However, you could do so either via startup script or provisioners and a configuration management tool, or by pre-baking configured images with Packer.

You will need to generate SSH keys as follows:

$ ssh-keygen -f ~/.ssh/gcloud_id_rsa
# press <Enter> when asked (twice) for a pass-phrase

Then download your credentials from Google Cloud Console; suggested path for downloaded file is ~/.gcloud/Terraform.json.

Optionally update variables.tf to specify a default value for the project_name variable, and check other variables.

After you run terraform apply on this configuration, it will automatically output the public IP address of the load balancer. After your instance registers, the LB should respond with a simple header:

<h1>Welcome to instance 0</h1>

The index may differ once you increase count of google_compute_instance (i.e. provision more instances).

To run, configure your Google Cloud provider as described in

https://www.terraform.io/docs/providers/google/index.html

Run with a command like this:

terraform apply \
	-var="region=us-central1" \
	-var="region_zone=us-central1-f" \
	-var="project_name=my-project-id-123" \
	-var="credentials_file_path=~/.gcloud/Terraform.json" \
	-var="public_key_path=~/.ssh/gcloud_id_rsa.pub" \
	-var="private_key_path=~/.ssh/gcloud_id_rsa"