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

example

  1. Set up the workflow
  1. Execute the workflow

image

--

image

Test Module

Generate Document

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

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

image

--

image

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

image

--

image

  1. Use the Module
module "foo" {
source = "github.com/${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::https://github.com/***/***.git?ref=*** for ***...

│ Error: Failed to download module

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


GitHub Actions Workflow

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

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