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/ (opens in a new tab)
Configuration
To replace all Terraform CLI commands with the Terragrunt CLI, you can create a custom workflow using the Terrateam configuration file.
workflows:
- tag_query: ""
terragrunt: true
This might not be what you want. To learn more about Terragrunt, see their official documentation (opens in a new tab).
Example repository
Gruntwork (opens in a new tab) maintains an
infrastructure-live (opens in a new tab)
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
- Terrateam installed against your GitHub organization. See our Getting Started guide.
- GitHub CLI (opens in a new tab)
Import the example repository
- 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"
- Create the new repository
gh repo create --private "$TERRAGRUNT_REPO"
- Clone the official
infrastructure-live
example repository
git clone --bare https://github.com/gruntwork-io/terragrunt-infrastructure-live-example
- Mirror the
infrastructure-live
repository with the--mirror
option
cd terragrunt-infrastructure-live-example.git
git push --mirror "https://github.com/$TERRAGRUNT_REPO"
- Clone your new
infrastructure-live
repository
cd ../
gh repo clone "$TERRAGRUNT_REPO" infrastructure-live
- Set the default branch back to
master
cd infrastructure-live
git checkout master
gh repo edit --default-branch master
Terrateam setup
- 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
- 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
The above configuration file will set up the following:
- A custom
TG_BUCKET_PREFIX
to be used for your Terraform state S3 bucket. Make sure you replace this value with something unique. - Enable the
terragrunt
cli in plan and apply operations - Properly trigger Terrateam operations when
terragrunt.hcl
files are updated
- Commit and push your changes
git commit -a -m "Changes for Terragrunt infra live and Terrateam"
git push
- 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 (opens in a new tab).
See the envcommon (opens in a new tab)
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.
The Terrateam GitHub application must be installed against module repositories for Terrateam to successfully clone the repository in Terrateam operations.
Start making changes
Now you can make changes and pull requests with your new infrastructure-live
repository using Terragrunt.