Skip to content

Latest commit

 

History

History

terraform-gcp-example

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

Terraform GCP Example

This folder contains a simple Terraform module that deploys resources in GCP to demonstrate how you can use Terratest to write automated tests for your GCP Terraform code. This module deploys a Compute Instance and gives that Instance a Name with the value specified in the instance_name variable. It also creates a Cloud Storage Bucket using the bucket_name and bucket_location variables.

Check out test/terraform_gcp_example_test.go to see how you can write automated tests for this module.

Note that the Compute Instance in this module doesn't actually do anything; it just runs a Vanilla Ubuntu 16.04 Image for demonstration purposes. For slightly more complicated, real-world examples of Terraform modules, see terraform-http-example and terraform-ssh-example.

WARNING: This module and the automated tests for it deploy real resources into your GCP account which can cost you money. The resources are all part of the GCP Free Tier, so if you haven't used that up, it should be free, but you are completely responsible for all GCP charges.

Running this module manually

  1. Sign up for GCP.
  2. Configure your GCP credentials using one of the supported methods for GCP CLI tools.
  3. Install Terraform and make sure it's in your PATH.
  4. Ensure the desired Project ID is set: export GOOGLE_CLOUD_PROJECT=terratest-ABCXYZ.
  5. Run terraform init.
  6. Run terraform apply.
  7. When you're done, run terraform destroy.

Running automated tests against this module

  1. Sign up for GCP.
  2. Configure your GCP credentials using the GCP CLI tools.
  3. Install Terraform and make sure it's on your PATH.
  4. Install Golang and make sure this code is checked out into your GOPATH.
  5. Set GOOGLE_CLOUD_PROJECT environment variable to your project name.
  6. cd test
  7. dep ensure
  8. go test -v -run TestTerraformGcpExample