Skip to content

Google Cloud Platform(GCP) and Terraform examples for GDG London workshop

License

Notifications You must be signed in to change notification settings

CloudNativeTech/gdg-terraform-gcp-workshop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Google Cloud Platform(GCP) and Terraform workshop at GDG London

This repository contains terraform examples to manage infrastructure on Google Cloud Platform(GCP).

⚠️ WARNING: Running examples in this repository may incur charges on your GCP account. We cannot be responsible for any charges you may incur.

Prerequisite

  1. Linux or MAC workstation.
  2. wget package installed on your workstation.
  3. Python 2.7 is installed.

How to install Terraform?

  1. Download terraform package from terraform.io/downloads.
wget https://releases.hashicorp.com/terraform/0.12.15/terraform_0.12.15_linux_amd64.zip -O /tmp/terraform.zip
  1. Unzip the terraform binary to a directory which is included in your system PATH.
sudo unzip /tmp/terraform.zip -d /usr/local/bin/
  1. Reload your shell.
exec -l $SHELL
  1. Verify installation.
terraform --help

How to install Google Cloud SDK?

  1. Set the directory for google-cloud-sdk.
export GCLOUD_PATH=$HOME

NOTE: You can change from $HOME to any directory path you want.

  1. Download google-cloud-sdk.
    For MAC users:
wget https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-271.0.0-darwin-x86_64.tar.gz -O $GCLOUD_PATH/google-cloud-sdk.tar.gz

For Linux users:

wget https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-271.0.0-linux-x86_64.tar.gz -O $GCLOUD_PATH/google-cloud-sdk.tar.gz
  1. Extract the downloaded package.
cd $GCLOUD_PATH
tar -zxvf google-cloud-sdk.tar.gz
  1. Run install.sh script to add Google Cloud SDK to your path.
./google-cloud-sdk/install.sh
  1. Reload Shell.
exec -l $SHELL

How to initialize Google Cloud SDK?

  1. Initialize the SDK.
gcloud init
  1. Accept to login to your Google account.
To continue, you must login. Would you like to log in (Y/n)? Y
  1. This will open your browser and prompt for permissions. Login with your Google account credentials and Allow.

  2. Select the preferred project and zone.

  3. You should now see the following message for successful initialization.

gcloud has now been configured!
You can use [gcloud config] to change more gcloud settings.

Your active configuration is: [default]
  1. Verify initialization.
gcloud auth list

How to run Terraform project?

  1. Generate google authentication token.
gcloud auth application-default login
  1. Navigate to terraform project directory.

  2. Fill the code where mentioned Update:

  3. Initialize terraform project.

terraform init
  1. Generate terraform execution plan.
terraform plan
  1. Run terraform apply, if plan looks good.
terraform apply
  1. For clean-up, destroy all the resources created by terraform.
terraform destroy

To revoke gcloud access from terminal

Run following command to revoke GCP credential from command-line.s

$> gcloud auth revoke
Note: Always remember to cleanup resources when NOT needed to avoid additional charges.

LICENSE

Please see LICENSE.txt