Skip to content

MeteorOps/terragrunt-gcp-projects

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Example GCP projects infrastructure for Terragrunt

Maintained by meteorops.com Terraform Version License

This repo, along with the terraform-gcp-modules, show an example file/folder structure you can use with Terragrunt to keep your Terraform code DRY. For background information, check out the Keep your Terraform code DRY section of the Terragrunt documentation.

How do you deploy the infrastructure in this repo?

Pre-requisites

  1. Install Terraform version 0.13.0 or newer and Terragrunt version v0.25.1 or newer.
  2. Fill in your GCP Project ID in my-project/project.hcl.
  3. Make sure gcloud CLI is installed and you are authenticated,otherwise run gcloud auth login.

Deploying a single module

  1. cd into the module's folder (e.g. cd my-project/us-central1/rnd-1/vpc).
  2. Run terragrunt plan to see the changes you're about to apply.
  3. If the plan looks good, run terragrunt apply.

Deploying all modules in an environment

  1. cd into the environment folder (e.g. cd my-project/us-central1/rnd-1).
  2. Run terragrunt run-all plan to see all the changes you're about to apply.
  3. If the plan looks good, run terragrunt run-all apply.

Testing the infrastructure after it's deployed

After each module is finished deploying, it will write a bunch of outputs to the screen. For example, the my-app will output something like the following:

Outputs:

ip = "35.240.219.84"

A minute or two after the deployment finishes, you should be able to test the ip output in your browser or with curl:

curl 35.240.219.84

Contact MeteorOps for DevOps & Cloud Consulting!

Destroying all modules in an environment

  1. cd into the environment folder (e.g. cd my-project/us-central1/rnd-1).
  2. Run terragrunt run-all plan -destroy to see all the destroy changes you're about to apply.
  3. If the plan looks good, run terragrunt run-all destroy.

How is the code in this repo organized?

The code in this repo uses the following folder hierarchy:

project
 └ _global
 └ region
    └ _global
    └ environment
       └ resource

Creating and using root (project) level variables

In the situation where you have multiple GCP projects or regions, you often have to pass common variables down to each of your modules. Rather than copy/pasting the same variables into each terragrunt.hcl file, in every region, and in every environment, you can inherit them from the inputs defined in the root terragrunt.hcl file.