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 create a custom workflow using the Terrateam configuration file.


# 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: ""
    terragrunt: true

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
gh repo create --private "$TERRAGRUNT_REPO"
  1. Clone the official infrastructure-live example repository
git clone --bare https://github.com/gruntwork-io/terragrunt-infrastructure-live-example
  1. Mirror the infrastructure-live repository with the --mirror option
cd terragrunt-infrastructure-live-example.git
git push --mirror "https://github.com/$TERRAGRUNT_REPO"
  1. Clone your new infrastructure-live repository
cd ../
gh repo clone "$TERRAGRUNT_REPO" infrastructure-live
  1. Set the default branch back to master
cd infrastructure-live
git checkout master
gh repo edit --default-branch master

Terrateam setup

  1. Create the Terrateam GitHub Workflow file
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
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
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