Skip to content
Ercan Ermis
Ercan Ermis

notes for everyone about cloud technology

  • Cloud
    • AWS
    • GCP
  • Container
    • Kubernetes
    • Docker
  • Linux
  • DevOps
  • Privacy Policy
  • Contact
Ercan Ermis

notes for everyone about cloud technology

How to call multiple terraform modules in a single terragrunt file

Ercan, May 7, 2024May 7, 2024

in Terragrunt, you can call multiple Terraform modules from a single Terragrunt configuration file by using the terraform block in combination with child configurations. This is typically done by organizing your Terragrunt configuration into a hierarchy where each module is referenced in its own Terragrunt file, but managed centrally using a parent Terragrunt file.

Here’s a basic outline of how you can structure this:

  1. Create a Parent Terragrunt File: This file won’t directly deploy any resources but will be used to configure common settings and orchestrate module deployment.
  2. Create Child Terragrunt Files for Each Module: Each module will have its own Terragrunt configuration file that specifies the source of the Terraform module and any necessary inputs.

Example Structure

Here’s an example directory structure:

/terraform-live
|-- terragrunt.hcl  # Parent configuration
|-- network
|   |-- terragrunt.hcl  # Module configuration for network
|-- app
|   |-- terragrunt.hcl  # Module configuration for app

Parent Terragrunt.hcl

# /terraform-live/terragrunt.hcl
remote_state {
  backend = "s3"
  config = {
    bucket         = "my-terraform-state"
    key            = "${path_relative_to_include()}/terraform.tfstate"
    region         = "us-west-1"
    encrypt        = true
    dynamodb_table = "my-lock-table"
  }
}

# Include all child configurations
include {
  path = find_in_parent_folders()
}

Child Terragrunt.hcl (e.g., for Network)

# /terraform-live/network/terragrunt.hcl
terraform {
  source = "git::https://example.com/network-module.git?ref=v1.0"
}

# Inputs specific to the network module
inputs = {
  vpc_id = "vpc-123456"
}

Usage

To apply all modules, you would typically navigate to each module directory and run Terragrunt commands, like terragrunt apply. You can also automate this with scripts or CI/CD workflows that iterate through module directories and execute Terragrunt commands.

This setup allows you to maintain a clear separation of concerns, reusable code, and consistency across environments while managing the deployment of multiple modules from a centralized configuration.

Share on Social Media
x facebook linkedin reddit
DevOps terraformterragrunt

Post navigation

Previous post
Next post
  • AWS (45)
    • Serverless (4)
  • Best (9)
  • DevOps (16)
  • Docker (10)
  • GCP (3)
  • Kubernetes (3)
  • Linux (13)
  • Uncategorized (6)

Recent Posts

  • Automating AWS CloudWatch Log Group Tagging with Python and Boto3
  • Automating AWS ECR Tagging with Python and Boto3
  • Automating ECR Image Cleanup with Bash
  • Update ECR Repositories with Bash Script
  • Why Automated Tests Are Essential in Your CI/CD Pipeline and Development Flow
  • Streamline Your AWS ECR Management with This Powerful Bash Script
  • Setting up DKIM for Google Workspace (Gmail) using Terraform and AWS Route 53
  • Automate AWS Site-to-Site VPN Monitoring
  • Optimizing Docker Images: Tips for Reducing Image Size and Build Time
  • Monitoring EC2 Disk Space with a Simple Bash Script and Slack Alerts
  • Securing Docker Containers: Best Practices for Container Security
  • Mastering Dockerfile: Writing Efficient, Scalable Container Builds
  • Migrating a Git Repository from GitLab to GitHub with GPG-Signed Commits
  • Accessing AWS Services in Private Subnets Without 0.0.0.0/0
  • Understanding AWS Regions, Availability Zones, and VPCs: A Comprehensive Guide
©2025 Ercan Ermis | WordPress Theme by SuperbThemes