gcp terraform with disk

View the Project on GitHub dwaiba/gcp-terraform

Table of Contents (Google Cloud with Terraform with disks)

  1. Google Cloud with Terraform
  2. Via Ansible terraform module
  3. Terraform graph
  4. Automatic provisioning
  5. Reporting bugs
  6. Patches and pull requests
  7. License
  8. Code of conduct

Google Cloud with Terraform

  1. Download and Install Terraform
  2. Please create Service Credential of type JSON via https://console.cloud.google.com/apis/credentials, download and save as google.json in credentials folder.
  3. Clone this repository
  4. Upload your public ssh key at https://console.cloud.google.com/compute/metadata/sshKeys and use the corresponding Username value in the console for default_user_name value in vars.tf
  5. terraform init && terraform plan -out "run.plan" && terraform apply "run.plan". Please note the Environment name prompted during plan may be dev/tst or any other stage.

Via Ansible terraform module

Ansible now has a terraform module and a playbook yml file is included in this repository with a sample inventory with localhost

  1. Clone this repository in the ansible box as cd /data && git clone https://github.com/dwaiba/gcp-terraform && cd gcp-terraform.

  2. Check the project_dir variable and change accordingly as required in gcp-terraform_playbook.yml file.

  3. Change the variables as required in gcp-terraform_playbook.yml.

  4. Kick as ansible-playbook -i inventory gcp-terraform_playbook.yml.

Terraform Graph

Please generate dot format (Graphviz) terraform configuration graphs for visual representation of the repo.

terraform graph | dot -Tsvg > graph.svg

Also, one can use Blast Radius on live initialized terraform project to view graph. Please shoot in dockerized format:

docker ps -a|grep blast-radius|awk '{print $1}'|xargs docker kill && rm -rf gcp-terraform && git clone https://github.com/dwaiba/gcp-terraform && cd gcp-terraform && terraform init && docker run --cap-add=SYS_ADMIN -dit --rm -p 5001:5000 -v $(pwd):/workdir:ro 28mm/blast-radius && cd ../

A live example is here for this project.

### Automatic Provisioning



  1. gcloud should be installed. Silent install is - export $USERNAME="<<you_user_name>>" && export SHARE_DATA=/data && su -c "export SHARE_DATA=/data && export CLOUDSDK_INSTALL_DIR=$SHARE_DATA export CLOUDSDK_CORE_DISABLE_PROMPTS=1 && curl https://sdk.cloud.google.com | bash" $USER_NAME && echo "source $SHARE_DATA/google-cloud-sdk/path.bash.inc" >> /etc/profile.d/gcloud.sh && echo "source $SHARE_DATA/google-cloud-sdk/completion.bash.inc" >> /etc/profile.d/gcloud.sh &&

  2. Please create Service Credential of type JSON via https://console.cloud.google.com/apis/credentials, download and save as google.json in credentials folder of the gcp-terraform

  3. Default user name is the local username


terraform init && terraform plan -var count_vms=2 -var default_user_name=<<your local username>> -var disk_default_size=20 -var environment=dev -var projectname=<<your-google-cloud-project-name>> -out "run.plan"


terraform apply "run.plan"


terraform destroy -var count_vms=2 -var default_user_name=buildadmin -var disk_default_size=20 -var environment=dev -var projectname=<<your-google-cloud-project-name>>

Reporting bugs

Please report bugs by opening an issue in the GitHub Issue Tracker. Bugs have auto template defined. Please view it here

Patches and pull requests

Patches can be submitted as GitHub pull requests. If using GitHub please make sure your branch applies to the current master as a ‘fast forward’ merge (i.e. without creating a merge commit). Use the git rebase command to update your branch to the current master if necessary.


Code of Conduct