Scaffolding / Boilerplate generator for new Terraform module projects
-
main.tf,variables.tf,outputs.tffiles to module root path -
.editorconfig,.gitignore,.gitattributesand.terraform-versionfiles to module root path -
Option to choose test framework
-
testdirectory with an example test based on test framework selection -
.pre-commit-config.yamlforterraform fmt,terraform-docs,check-merge-conflictand (go fmt,golint) /rubocop -
exampledirectory with module usage tf files
- terraform
pro tip: use tfenv - terraform-docs
- pre-commit
- For tests
- To use generator using Docker, Install Docker
recommended - To use generator using Nodejs, Install nodejs
pro tip: use nvm
To use the included generator execute the below command in shell and provide your answers to the prompts.
For Terraform version 1
docker run --rm -it -v $(pwd):/generated -e myuid="$(id -u):$(id -g)" sudokar/generator-tf-moduleFor 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.0For 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'...
? 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-terraformProject 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
Step 1
On the generated module's root path, Initialize git repository
git initStep 2
On the generated module's root path, Install pre-commit hooks
pre-commit installStep 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/assertFound a bug? feel free to raise an issue.
Pull requests are always welcome. Keen to review and merge asap.
Like the generator?
Or, Add a star ⭐ to the repository
This project is authored and maintained by sudokar
MIT
