Home

Awesome

Terraform module generator

npm version npm Docker Pulls Docker Image Version (latest by date)

Scaffolding / Boilerplate generator for new Terraform module projects

Features

Prerequisites

Installation

Usage

To use the included generator execute the below command in shell and provide your answers to the prompts.

With Docker

For Terraform version 1

docker run --rm -it -v $(pwd):/generated -e myuid="$(id -u):$(id -g)" sudokar/generator-tf-module

For Terraform versions 0.15, 0.14 and 0.13

docker run --rm -it -v $(pwd):/generated -e myuid="$(id -u):$(id -g)" sudokar/generator-tf-module:0.9.0

With NodeJs

For Terraform version 1

npx -p yo -p generator-tf-module -c 'yo tf-module'

For Terraform versions 0.15, 0.14 and 0.13

npx -p yo -p generator-tf-module@0.9.0 -c 'yo tf-module'

Prompts

...
? Enter name for the new terraform module :  example-module
? Enter description for the new terraform module :  Example terraform module
? Enter author name :  sudokar
? Choose test framework (Use arrow keys)
❯ Terratest
  kitchen-terraform

Project layout generated for the new module with Terratest selection

example-module
├── .editorconfig
├── .gitattributes
├── .gitignore
├── .pre-commit-config.yaml
├── .terraform-version
├── README.md
├── main.tf
├── outputs.tf
├── variables.tf
├── example
│   ├── main.tf
│   ├── outputs.tf
│   └── variables.tf
├── test
    └── example_test.go

Project layout generated for the new module with kitchen-terraform selection

example-module
├── .editorconfig
├── .gitattributes
├── .gitignore
├── .pre-commit-config.yaml
├── .terraform-version
├── .ruby-version
├── .kitchen.yml
├── Gemfile
├── README.md
├── main.tf
├── outputs.tf
├── variables.tf
├── example
│   ├── main.tf
│   ├── outputs.tf
│   └── variables.tf
├── test
    └── integration
        └── default
            └── example_spec.rb

Post generation steps

Step 1

On the generated module's root path, Initialize git repository

git init

Step 2

On the generated module's root path, Install pre-commit hooks

pre-commit install

Step 3 (Applicable only for terratest)

For golang tests, get below libs

go get github.com/gruntwork-io/terratest/modules/terraform
go get github.com/stretchr/testify/assert

Contribution

Found a bug? feel free to raise an issue.
Pull requests are always welcome. Keen to review and merge asap.

Support

Like the generator?

Click to <a href="https://www.buymeacoffee.com/sudokar" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy Me A Coffee" height="50" width="250"></a>

Or, Add a star :star: to the repository

Maintainer

This project is authored and maintained by sudokar

License

MIT