Maintained by @JinLee794
This repo shows 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.
Be sure to read through the Terragrunt documentation on DRY Architectures to understand the features of Terragrunt used in this folder organization.
Note: This code is solely for demonstration purposes. This is not production-ready code, so use at your own risk. If you are interested in battle-tested, production-ready Terraform code, check out Gruntwork.
- Install Terraform version
1.1.7
and Terragrunt versionv0.36.0
or newer. - Configure your remote state backend values within the
common.hcl
configuration files - Configure your Azure credentials using one of the supported authentication mechanisms.
- Fill in details relevant to your subscription in the following files:
cd
into the module's folder (e.g.cd Live/nonprod/ES_JINLE/Network/resource-group
).- Run
terragrunt plan
to see the changes you're about to apply. - If the plan looks good, run
terragrunt apply
.
cd
into the layer folder (e.g.cd Live/nonprod/ES_JINLE/Network
).- 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
.
The code in this repo uses the following folder hierarchy:
Live
└ environment
└ subscription
└ layer
└ resource
Modules
└ module
Where:
-
environment: At the top level is the
nonprod
orprod
grouping to accommodate for multi-subscription Azure environments, while assuming each subscription will be designated for either production on non-production workloads. -
subscription: Within each environment, there will be an Azure subscription name to directly reflect the resource organization structure on both Azure and in code.
-
layer: Within each subscription, there will be one or more "layers", such as
Compute
,Network
, etc. These are logical groupings of resources that also share a common attribute file (layer.hcl
) to further allow you to keep your code 'DRY'. Such a structure allows quick and easy configuration for numerous resources all at a centralized location. -
resource: Within each environment, you deploy all the resources for that environment, such as Windows VM Instances, Virtual Network, Subnets, Network Security Groups, Bastions, and so on. Note that the Terraform code for most of these resources lives in the
/Modules/
directory.