• Stars
    star
    257
  • Rank 158,728 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 5 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Project scaffolding for Terraform

Terraform module generator

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

Scaffolding / Boilerplate generator for new Terraform module projects

Features

  • main.tf, variables.tf,outputs.tf files to module root path

  • .editorconfig, .gitignore, .gitattributes and .terraform-version files to module root path

  • Option to choose test framework

  • test directory with an example test based on test framework selection

  • .pre-commit-config.yaml for terraform fmt, terraform-docs, check-merge-conflict and (go fmt, golint) / rubocop

  • example directory with module usage tf files

Prerequisites

Installation

  • To use generator using Docker, Install Docker recommended
  • To use generator using Nodejs, Install nodejs pro tip: use nvm

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 [email protected] -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 Buy Me A Coffee

Or, Add a star โญ to the repository

Maintainer

This project is authored and maintained by sudokar

License

MIT