Skip to main content

Manage Terraform Modules

tfaction's required version: >= v0.5.0 #221

tfaction supports scaffolding, testing, and releasing Terraform Modules.

Please add a file tfaction_module.yaml in the Module directory. tfaction detects Modules with this file. Currently, tfaction doesn't read the content, so there is no problem even if the content is empty.


Scaffold Module

💡 If you don't want to create pull requests by GitHub App, please see Support skipping creating pull requests.

You can scaffold a new Terraform Module by GitHub Actions.

  1. Prepare templates of Terraform Modules


  1. Set up the workflow
  1. Execute the workflow




Test Module

Generate Document

The action test-module generates the document by terraform-docs.

If is generated or updated, a commit is pushed to the feature branch $GITHUB_HEAD_REF.




Release Module

Instead of Local paths Source, we recommend creating a tag and fix the version by GitHub Source.

  1. Set up the workflow
  1. Release a new version by executing the workflow




  1. Use the Module
module "foo" {
source = "${GitHub Repository full name}//${module path}?ref=${GitHub tag name}"

💡 Trouble shooting about downloading Private Modules

If it fails to download Private Modules in terraform init, you may have to run gh auth setup-git with GitHub Access Token.

Error of terraform init

Upgrading modules...
Downloading git::***/***.git?ref=*** for ***...

│ Error: Failed to download module

│ Could not download module "***" ( source code
│ from
│ "git::***/***.git?ref=***":
│ error downloading
│ '***/***.git?ref=***':
│ /usr/bin/git exited with 128: Cloning into
│ '.terraform/modules/***'...
│ fatal: could not read Username for '': No such device or
│ address

GitHub Actions Workflow

# This is required to download private modules in `terraform init`
- run: gh auth setup-git
GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}

- uses: suzuki-shunsuke/tfaction/setup@v0.5.0
github_app_token: ${{ steps.generate_token.outputs.token }}