The set of files used to describe infrastructure in Terraform is known as a Terraform configuration. Your git repository contains a starter configuration in the base directory. This lab will take you through te process of connecting a service account with Terraform so you can make cloud infrastructure from the command line.

Important

You should already have done the steps in Terraform Quickstart for GCP

## Step 1: Setup the Key File#

In the Terraform Quickstart you should have:

1. Created a GCP project

2. Created a service account

To use the Terraform configuration in the project the key should be placed in the file secrets/cis-91.key. The secrets directory is excluded from git so there’s no risk that you’ll accidentally check the key in to GitHub.

Want to start a new project?

There is a shell script bin/create-project.sh that automates the process. Execute it like this:

$terraform init  ## Step 4: Create the Base VM# Now you can create the base virtual machine with Terraform. $ terraform apply


If it worked you will see this output at the end:

Outputs:

external-ip = "34.69.145.72"


## Step 5: SSH Into Your New VM#

The gcloud command automates the configuration of SSH. When you add or remove VMs you can tell gcloud to refresh your ~/.ssh/config file with these two commands:

$gcloud compute config-ssh --remove$ gcloud compute config-ssh


Error

If the second command fails you haven’t set the default project. Follow the instructions in the error message.

The config-ssh command creates aliases but you should be able to login directly using the IP address:

\$ ssh -i ~/.ssh/google_compute_engine 34.69.145.72


Note

Replace 34.69.145.72 with the IP address given to you by Terraform

## Turn In#

Turn in a screenshot of you SSH’ed into your new VM