Terraform module generator
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
forterraform fmt
,terraform-docs
,check-merge-conflict
and (go fmt
,golint
) /rubocop
-
example
directory with module usage tf files
Prerequisites
- terraform
pro tip: use tfenv
- terraform-docs
- pre-commit
- For tests
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?
Or, Add a star โญ to the repository
Maintainer
This project is authored and maintained by sudokar
License
MIT