Git Product home page Git Product logo

terraform-module-template's Introduction

Template repo for Terraform modules

This repository contains my template for creating Terraform modules, yes even my root modules. This template is based on the best practices I have learned and the HashiCorp style guide.

Tools that I use

I use a wide array of tools to make things easier for me.

  • 1Password: Password and Secret storage
    • brew install 1password
  • 1Password - CLI: Allows for access to 1Password via environment variables and shell scripts.
    • brew install 1password-cli
  • Direnv: Manages dynamic environment variables based on the directory.
    • brew install direnv
  • Task: Replacement for GNU make. Uses YAML files.
    • brew install go-task
  • Terraform: Kind of the whole point here ๐Ÿ˜„
    • brew install hashicorp/tap/terraform
  • git: Another obvious one ๐Ÿ˜ƒ
    • brew install git
  • pre-commit: Provides a method for running scripts and other tools during the git commit process.
    • brew install pre-commit
  • trufflehog: Scans your git repo for committed secrets ๐Ÿ˜ฑ.
    • brew install trufflesecurity/trufflehog/trufflehog
  • autotag: Automatically creates git tags based on the commit message. Used to create semantic version tags in GitHub Actions pipeline. (Not installed locally, but you could)
    • brew install pantheon-systems/autotag/autotag

Tools needed for the Pre-commit hooks that I use

All of these tools can be used standalone, but I use them as part of the git commit process.

  • terraform-docs: Dynamically updates your README.md with information on the inputs, outputs, and requirements of your module.
    • brew install terraform-docs
  • infracost: Gives you a cost estimate for the cloud resources your module would deploy.
    • brew install infracost
  • jq: A lightweight and flexible command-line JSON processor. required for terraform_validate with --retry-once-with-cleanup flag, and for infracost_breakdown hook.
    • brew install jq
  • TFLint: A Terraform linter that checks for best practices and errors in your Terraform code.
    • brew install tflint
  • One or more of these terraform security scanning tools

Miscellaneous tools

  • tfvars: This tool helps you manage Terraform variables. It allows you to store Terraform variables in a central location, and it also provides a way to encrypt Terraform variables.
  • inframap: Inframap is a tool that can be used to visualize your Terraform infrastructure. It reads your tfstate or HCL to generate a graph specific for each provider, showing only the resources that are most important/relevant.
  • driftctl: driftctl detects infrastructure drift by comparing actual resources with Terraform configuration, identifying changes or drift in attributes.
  • Terraspace: Terraspace is a framework that simplifies the development and deployment of Terraform infrastructure, offering automated module generation and integrated testing.
  • Terraform Compliance: Terraform Compliance is a security and compliance scanner for Terraform code, allowing you to define and verify policies as code.

Terraform Maintenance tools

Here are a couple of tools I use to help with managing Terraform versions.

  • TFSwitch: Used to switch the version of terraform installed based on the directory you are in or the version constraint in your terraform code.
    • brew install warrensbox/tap/tfswitch
  • tfupdate: Used to update the version constraints in your terraform code for core, providers and modules.
    • brew install tfupdate
  • TFTUI: TFTUI is a powerful textual UI that empowers users to effortlessly view and interact with their Terraform state.
    • brew install idoavrah/tap/tftui

Code Editor

I use Visual Studio Code as my code editor. I have included my settings and extensions in the .vscode directory, so they should be automatically installed when you open the project. They are also listed below.

Extensions

I use the following extensions for VS Code.

Settings

I use the following settings for VS Code.

{
  "[sentinel]": {
    "editor.defaultFormatter": "hashicorp.terraform"
  },
  "[terraform]": {
    "editor.defaultFormatter": "hashicorp.terraform"
  },
  "[tfvars]": {
    "editor.defaultFormatter": "hashicorp.terraform"
  },
  "editor.bracketPairColorization.enabled": true,
  "editor.formatOnSave": true,
  "editor.rulers": [
    {
      "color": "#A5FF90",
      "column": 80
    },
    {
      "color": "#FF628C",
      "column": 100
    }
  ],
  "editor.tabCompletion": "on",
  "editor.tabSize": 2,
  "files.associations": {
    "*.hcl": "terraform",
    "*.nomad": "terraform",
    "*.policy": "sentinel"
  },
  "terraform.indexing": {
    "delay": 500,
    "enabled": false,
    "exclude": [".terraform/**/*", "**/.terraform/**/*"],
    "liveIndexing": false
  },
  "terraform.languageServer.enable": true
}

Example config files

I've included example config files for some of the tools.

direnv: Rename .envrc.example to .envrc and update.

pre-commit: Review .pre-commit-config.yaml to enable/disable hooks.

terraform-docs: Review .terraform-docs.yml to adjust document formatting options.

TFLint: Review .tflint.hcl

Task: Review Taskfile.yaml and or remove tasks.

Terraform: Rename terraform.tfvars.example to terraform.tfvars and update.

Terraform Docs Dynamic section

Everything above this should be removed and replaced with your module description.

The following two lines specify where the terraform-docs dynamic content will be placed.

Requirements

Name Version
terraform ~> 1.0
google ~>4.55
hcp ~>0.54

Providers

No providers.

Modules

No modules.

Resources

No resources.

Inputs

No inputs.

Outputs

No outputs.

terraform-module-template's People

Contributors

dependabot[bot] avatar methridge avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

terraform-module-template's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

This repository currently has no open or pending branches.

Detected dependencies

github-actions
.github/workflows/main-release.yaml
  • actions/checkout v4
.github/workflows/pr-actionlint.yaml
  • actions/checkout v4
terraform
providers.tf
terraform.tf
  • google ~> 5.0
  • hcp ~> 0.91
  • hashicorp/terraform ~> 1.0
tflint-plugin
.tflint.hcl
  • terraform-linters/tflint-ruleset-aws 0.31.0
  • terraform-linters/tflint-ruleset-azurerm 0.26.0
  • terraform-linters/tflint-ruleset-google 0.29.0

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.