For example, the mysql module will have its key parameter resolve to mysql/terraform.tfstate and the frontend-app module will have its key parameter resolve to frontend-app/terraform.tfstate. We typically use this in a root terragrunt.hcl file so that each Terraform child module stores its Terraform state at a different key. Path_relative_to_include(): This function returns the relative path between the current terragrunt.hcl file and the path specified in its include block.
#Terraform if block code#
This way, you don’t have to hard code the path parameter in every module. In the example above, the call to find_in_parent_folders() in mysql/terragrunt.hcl will return /your-root-folder/terragrunt.hcl. The terragrunt.hcl files above use two Terragrunt built-in functions:įind_in_parent_folders(): This function returns the absolute path to the first terragrunt.hcl file it finds in the parent folders above the current terragrunt.hcl file. The next time you run terragrunt, it will automatically configure all the settings in the remote_nfig block, if they aren’t configured already, by calling terraform init. It behaves exactly as if you had copy/pasted the Terraform configuration from the included file remote_state configuration into mysql/terragrunt.hcl, but this approach is much easier to maintain! The include block tells Terragrunt to use the exact same Terragrunt configuration from the terragrunt.hcl file specified via the path parameter.
#Terraform if block how to#
The short version: how to use lock files with Terragrunt.Use-case: I use locals or dependencies in terragrunt.hcl, and the terraform output isn’t what I expected.Configuring Terragrunt to assume an IAM role.Limiting the module execution parallelism.Execute Terraform commands on multiple modules at once.Using read_terragrunt_config to DRY parent configurations.Using exposed includes to override common configurations.Using include to DRY common Terragrunt config.Create remote state and locking resources automatically.Using the generate property to generate terraform code for managing remote state.Rules for merging parent and child configurations.Filling in remote state settings with Terragrunt.Keep your remote state configuration DRY.DRY common Terraform code with Terragrunt generate blocks.Using Terragrunt with private Git repos.Important gotcha: working with relative file paths.Achieve DRY Terraform code and immutable infrastructure.Promote immutable, versioned Terraform modules across environments.