Google Cloud Platform(GCP) and Terraform workshop at GDG London
This repository contains terraform examples to manage infrastructure on Google Cloud Platform(GCP).
:warning: WARNING: Running examples in this repository may incur charges on your GCP account. We cannot be responsible for any charges you may incur.
Prerequisite
- Linux or MAC workstation.
wgetpackage installed on your workstation.- Python 2.7 is installed.
How to install Terraform?
-
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 -
Unzip the terraform binary to a directory which is included in your system
PATH.sudo unzip /tmp/terraform.zip -d /usr/local/bin/ -
Reload your shell.
exec -l $SHELL -
Verify installation.
terraform --help
How to install Google Cloud SDK?
-
Set the directory for
google-cloud-sdk.export GCLOUD_PATH=$HOMENOTE: You can change from
$HOMEto any directory path you want. -
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.gzFor 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 -
Extract the downloaded package.
cd $GCLOUD_PATH tar -zxvf google-cloud-sdk.tar.gz -
Run
install.shscript to add Google Cloud SDK to your path../google-cloud-sdk/install.sh -
Reload Shell.
exec -l $SHELL
How to initialize Google Cloud SDK?
-
Initialize the SDK.
gcloud init -
Accept to login to your Google account.
To continue, you must login. Would you like to log in (Y/n)? Y -
This will open your browser and prompt for permissions. Login with your Google account credentials and Allow.
-
Select the preferred
projectandzone. -
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]
- Verify initialization.
gcloud auth list
How to run Terraform project?
-
Generate google authentication token.
gcloud auth application-default login -
Navigate to terraform project directory.
-
Fill the code where mentioned
Update: -
Initialize terraform project.
terraform init -
Generate terraform execution plan.
terraform plan -
Run terraform apply, if plan looks good.
terraform apply -
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