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.
- Linux or MAC workstation.
wget
package installed on your workstation.- Python 2.7 is installed.
- 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
- Set the directory for
google-cloud-sdk
.
export GCLOUD_PATH=$HOME
NOTE: You can change from $HOME
to 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.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
- Extract the downloaded package.
cd $GCLOUD_PATH
tar -zxvf google-cloud-sdk.tar.gz
- Run
install.sh
script to add Google Cloud SDK to your path.
./google-cloud-sdk/install.sh
- Reload Shell.
exec -l $SHELL
- 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
project
andzone
. -
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
- 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
Run following command to revoke GCP credential from command-line.s
$> gcloud auth revoke
Please see LICENSE.txt