Skip to content

Best Practices for a Terraform Module and supporting content

License

Notifications You must be signed in to change notification settings

Lachlan-White/terraform-module-template

Repository files navigation

Terraform Module Template

Overview

This repository is a template that can be used as a standard for terraform module creations for any provider or platform.

The goal of this template is to establish some best practices in terms of structure and guidance on how to structure, assemble and some guidance on when to use a module.

What is a Module?

A module is a container for multiple resources that are used together. Modules can be used to create lightweight abstractions, so that you can describe your infrastructure in terms of its architecture, rather than directly in terms of physical objects.

When to use a Module

  • One or more resources are used in direct conjunction with each other

    • Such as NICs and Disks added to a Virtual Machine Resource to simplify consumption
  • One or mode modules are used in direct conjunction with each other, to form a standard pattern or architecture

  • Opinionated configuration adds additional value, in which repetition would otherwise ensue

    • Such as Complex Validations, Security Configurations etc

When not to use a module

  • To create a simple wrapper around a resource, that adds no additional value:

    • Such as an Azure load Balancer, where the configuration is always different
  • The modules' purpose is solely to be consumed by another high-level module

How to use this template

Step 1: Click the Use this template button at the top of the page

Step 2: Select the Owner / Organisation and Name of your new repository, along with privacy settings of the repository

Step 3: Delete the README.md file and rename README.new to README.md

Step 4: Start building your module

File Specific Guidance

Within every file is some guidance on the purpose of these files, and when to use them.