Gjorgji Jovanovski Gjorgji Jovanovski

Automate Terraform Module Releases.

If you’ve managed a growing collection of Terraform modules in a monorepo, you know how quickly complexity can escalate. What begins with a few reusable modules often leads to versioning conflicts, outdated documentation, and manual release processes that drain your team’s time and energy.

This scenario is common. Many teams face these challenges as they scale their Infrastructure as Code (IaC) with Terraform. Fortunately, there’s a more efficient approach. This guide explores how to automate the release process for your Terraform modules using the Terraform Module Releaser GitHub Action.


Why Automate Terraform Module Releases?

As your infrastructure grows, common patterns are naturally abstracted into reusable modules; much like functions in programming. Each module encapsulates a specific capability, such as provisioning an AWS S3 bucket or configuring a VPC. With defined inputs and outputs, these modules can be reused across your environment, resulting in cleaner code and easier maintenance.

However, as modules evolve, we are back at square one having to solve yet another complexity issue. Without automation, teams often resort to manual processes that are error-prone and time-consuming. This can lead to:

  • Inconsistent Releases: Without a standardized process, releases can vary in quality and completeness, causing confusion and frustration.

  • Lack of Visibility: Teams may struggle to understand which modules are available, their versions, and how to use them.

  • Increased Technical Debt: As modules grow more complex, the risk of introducing bugs and inconsistencies rises, accumulating technical debt that’s hard to manage.

These issues introduce friction and increase the risk of infrastructure failures. Automating the release process brings discipline to your Terraform workflow, much like automated testing and CI/CD pipelines do for application code. It ensures that modules are reliably versioned, clearly documented, and consistently published.


What Does the Terraform Module Releaser Do?

The Terraform Module Releaser GitHub Action streamlines the management of Terraform modules in monorepos. Here’s how it enhances your workflow:

  • Automated Versioning: Uses commit messages following the Conventional Commits specification to determine appropriate semantic versioning (major, minor, patch) for each module.
  • Targeted Releases: Creates Git tags and GitHub releases that include only the relevant module directory content; enabling independent releases in a monorepo.
  • Dynamic Documentation: Automatically generates documentation for each module, including usage examples, input/output variables, and detailed changelogs, which are pushed to the GitHub Wiki.
  • Automated Cleanup: Detects and removes tags associated with deleted modules, keeping your repository clean.
  • Customizable Configuration: Offers sensible defaults with the flexibility to adjust exclude patterns, keywords, and source link formats to suit your project.
  • Integration Outputs: Provides outputs like all-modules-map (a JSON object mapping module names to metadata), enabling further automation and integration into CI/CD pipelines.

In short, it removes the grunt work from module management, letting you focus on building and improving infrastructure.


Quickstart

Prerequisites

GitHub Repository

A GitHub repository to store your Terraform modules.

Enable the GitHub Wiki

  • Go to your repository’s Settings.
  • Under Features, check the Wikis option.
  • Navigate to the Wiki tab and create the first page (e.g., “Home”) to initialize the wiki.

Add the Workflow

  • Create a .github/workflows directory if it doesn’t exist.

  • Add a workflow file named terraform-module-releaser.yml:

    name: Terraform - Module Releaser
    
    on:
    pull_request:
       types: [opened, reopened, synchronize, closed]
       branches:
          - main
    
    permissions:
    contents: write
    pull-requests: write
    
    jobs:
    release:
       runs-on: ubuntu-latest
       steps:
          - name: Checkout code
          uses: actions/checkout@v4
    
          - name: Terraform Module Releaser
          uses: techpivot/terraform-module-releaser@v1
          with:
             major-keywords: breaking change
             minor-keywords: feat
             patch-keywords: fix,chore,docs
             default-first-tag: v0.1.0
             terraform-docs-version: v0.20.0
             delete-legacy-tags: true
             use-ssh-source-format: false
    

Create Your First Module

  1. Create and Commit Modules

    • Create a new branch for your module (e.g., feat/add-s3-module).
    • Add your Terraform module (e.g., aws/s3) to the repository.
    • Use Conventional Commits in your commit messages (e.g., feat: add s3 module) and commit your changes.
  2. Open a Pull Request

    • Push your branch and open a PR against main. demo-tf-module-releaser-1 The workflow will run and comment on the PR, showing what will be released.
  3. Merge and Release

    • After merging, the workflow will create a release and update the wiki with the latest module documentation. demo-tf-module-releaser-2 Once merged, the action posts a release notification comment. demo-tf-module-releaser-3 The action creates a GitHub release and a corresponding tag for each module.
  4. Check the Wiki

    • Visit the Wiki tab to view the latest module documentation and usage examples. demo-tf-module-releaser-4 The documentation includes usage info, version requirements, and providers. demo-tf-module-releaser-5 You’ll also see a list of resources, input variables (with types and defaults), and outputs.

Additional Considerations

  • Automate Code Validation: Add a workflow to run terraform init, terraform fmt, and terraform validate on PRs and pushes to ensure consistent, error-free code.
  • Integrate Dependabot for Dependency Management: Use a .github/dependabot.yml configuration to automate updates for Terraform providers and modules. Dependabot can create PRs for outdated dependencies.
  • Enhance Validation with Additional Tools: Extend validation with tools like tflint and terrascan for deeper analysis and security scanning.

Conclusion

Automating your Terraform module releases with the Terraform Module Releaser GitHub Action allows your team to focus on infrastructure development; not repetitive release tasks. Documentation stays up to date, releases are predictable, and your workflow becomes faster and more reliable.

If you found this useful, ⭐ the Terraform Module Releaser GitHub repository to show your support for the maintainer.