Skip to content

Terragrunt

Terrateam Configuration Terrateam behavior can be configured via a config.yml. This file is located in a directory named .terrateam at the root of your Terraform repository: .terrateam/config.yml.

See Configuration documentation for details.

What is Terragrunt?

Terragrunt is a thin wrapper that provides extra tools for keeping your configurations DRY, working with multiple Terraform modules, and managing remote state. — https://terragrunt.gruntwork.io/

Configuration

To replace all Terraform CLI commands with the Terragrunt CLI, you can specify the engine using the Terrateam configuration file. The engine configuration can be specified globally or overridden in a custom workflow.

engine:
name: terragrunt
# Trigger Terrateam operations when any
# terragrunt.hcl file is modified
# except for the root terragrunt.hcl
dirs:
"**/terragrunt.hcl":
when_modified:
file_patterns: ['${DIR}/terragrunt.hcl']
'.':
when_modified:
file_patterns: []

Or in the workflows section:

# Trigger Terrateam operations when any
# terragrunt.hcl file is modified
# except for the root terragrunt.hcl
dirs:
"**/terragrunt.hcl":
when_modified:
file_patterns: ['${DIR}/terragrunt.hcl']
'.':
when_modified:
file_patterns: []
workflows:
- tag_query: ""
engine:
name: terragrunt

This might not be what you want. To learn more about Terragrunt, see their official documentation.

Example repository

Gruntwork maintains an infrastructure-live repository for Terragrunt. This repo contains an example repository layout you can use with Terragrunt. The following documentation will describe how to use Terragrunt and Terrateam together with the infrastructure-live example repository as a foundation.

Prerequisites

Import the example repository

  1. Export your organization/repository combination that you want to use for your Terragrunt code
export GITHUB_ORG="<MY_GITHUB_ORG>"
export TERRAGRUNT_REPO="${GITHUB_ORG}/infrastructure-live"
  1. Create the new repository
Terminal window
gh repo create --private "$TERRAGRUNT_REPO"
  1. Clone the official infrastructure-live example repository
Terminal window
git clone --bare https://github.com/gruntwork-io/terragrunt-infrastructure-live-example
  1. Mirror the infrastructure-live repository with the --mirror option
Terminal window
cd terragrunt-infrastructure-live-example.git
git push --mirror "https://github.com/$TERRAGRUNT_REPO"
  1. Clone your new infrastructure-live repository
Terminal window
cd ../
gh repo clone "$TERRAGRUNT_REPO" infrastructure-live
  1. Set the default branch back to master
Terminal window
cd infrastructure-live
git checkout master
gh repo edit --default-branch master

Terrateam setup

  1. Create the Terrateam GitHub Workflow file
Terminal window
mkdir -p .github/workflows
curl -o .github/workflows/terrateam.yml https://raw.githubusercontent.com/terrateamio/terrateam-example/main/github/actions/workflows/default/terrateam.yml
git add .github
  1. Create a custom Terrateam configuration file
Terminal window
mkdir .terrateam
curl -o .terrateam/config.yml https://raw.githubusercontent.com/terrateamio/terrateam-example/main/terrateam/terragrunt-infrastructure-live/config.yml
git add .terrateam
  1. Commit and push your changes
Terminal window
git commit -a -m "Changes for Terragrunt infra live and Terrateam"
git push
  1. Complete the Cloud Provider Setup for your new infrastructure-live repository

Modules

The infrastructure-live example repository will pull modules in from the terragrunt-infrastructure-modules-example repository found here. See the envcommon terragrunt.hcl files for the base_source_url definitions.

You can continue to use this repository but it’s recommended to mirror the repository into your GitHub organization and reference the new URL in your base_source_url definitions.

Start making changes

Now you can make changes and pull requests with your new infrastructure-live repository using Terragrunt.

Terragrunt Pull Request Files Changed Terragrunt Plan Output

We use cookies and similar technologies to provide certain features, enhance the user experience and deliver content that is relevant to your interests. Depending on their purpose, analysis and marketing cookies may be used in addition to technically necessary cookies. By clicking on "Agree and continue", you declare your consent to the use of the aforementioned cookies. Here you can make detailed settings or revoke your consent (in part if necessary) with effect for the future. For further information, please refer to our Privacy Policy .