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.
- Install Terraform version
0.13.0
or newer and Terragrunt versionv0.25.1
or newer. - Fill in your GCP Project ID in
my-project/project.hcl
. - Make sure gcloud CLI is installed and you are authenticated,otherwise run
gcloud auth login
.
cd
into the module's folder (e.g.cd my-project/us-central1/rnd-1/vpc
).- Run
terragrunt plan
to see the changes you're about to apply. - If the plan looks good, run
terragrunt apply
.
cd
into the environment folder (e.g.cd my-project/us-central1/rnd-1
).- Run
terragrunt run-all plan
to see all the changes you're about to apply. - If the plan looks good, run
terragrunt run-all apply
.
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!
cd
into the environment folder (e.g.cd my-project/us-central1/rnd-1
).- Run
terragrunt run-all plan -destroy
to see all the destroy changes you're about to apply. - If the plan looks good, run
terragrunt run-all destroy
.
The code in this repo uses the following folder hierarchy:
project
└ _global
└ region
└ _global
└ environment
└ resource
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.