项目作者: sudokar

项目描述 :
Project scaffolding for Terraform
高级语言: JavaScript
项目地址: git://github.com/sudokar/generator-tf-module.git
创建时间: 2019-03-10T12:31:37Z
项目社区:https://github.com/sudokar/generator-tf-module

开源协议:MIT License

下载


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

  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

  1. 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

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

For Terraform versions 0.15, 0.14 and 0.13

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

Prompts

  1. ...
  2. ? Enter name for the new terraform module : example-module
  3. ? Enter description for the new terraform module : Example terraform module
  4. ? Enter author name : sudokar
  5. ? Choose test framework (Use arrow keys)
  6. Terratest
  7. kitchen-terraform

Project layout generated for the new module with Terratest selection

  1. example-module
  2. ├── .editorconfig
  3. ├── .gitattributes
  4. ├── .gitignore
  5. ├── .pre-commit-config.yaml
  6. ├── .terraform-version
  7. ├── README.md
  8. ├── main.tf
  9. ├── outputs.tf
  10. ├── variables.tf
  11. ├── example
  12. ├── main.tf
  13. ├── outputs.tf
  14. └── variables.tf
  15. ├── test
  16. └── example_test.go

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

  1. example-module
  2. ├── .editorconfig
  3. ├── .gitattributes
  4. ├── .gitignore
  5. ├── .pre-commit-config.yaml
  6. ├── .terraform-version
  7. ├── .ruby-version
  8. ├── .kitchen.yml
  9. ├── Gemfile
  10. ├── README.md
  11. ├── main.tf
  12. ├── outputs.tf
  13. ├── variables.tf
  14. ├── example
  15. ├── main.tf
  16. ├── outputs.tf
  17. └── variables.tf
  18. ├── test
  19. └── integration
  20. └── default
  21. └── example_spec.rb

Post generation steps

Step 1

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

  1. git init

Step 2

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

  1. pre-commit install

Step 3 (Applicable only for terratest)

For golang tests, get below libs

  1. go get github.com/gruntwork-io/terratest/modules/terraform
  2. 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 :star: to the repository

Maintainer

This project is authored and maintained by sudokar

License

MIT