Skip to content

bsnape/terraform-style-guide

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 

Repository files navigation

Terraform Style Guide

This is intended to be a guide of Terraform syntax and general best practices.

As Terraform utilises HCL, you may wish to take a detailed look at its syntax guide.

Inspired by The Ruby Style Guide and The Puppet Style Guide.

Table of Contents

Code Layout

Indentation should be 2 spaces (soft tabs). No hard tabs.

Attribute assignments (=) should be aligned for clarity.

// bad
resource "aws_security_group" "main" {
    name = "${var.name}"
    description = "Security Group ${var.name}"
    vpc_id = "${var.vpc_id}"
    tags {
        Name = "${var.name}"
    }
}

// good
resource "aws_security_group" "main" {
  name        = "${var.name}"
  description = "Security Group ${var.name}"
  vpc_id      = "${var.vpc_id}"
  tags {
    Name = "${var.name}"
  }
}

Modules

Variables

Variables should be provided in a variables.tf file at the root of your project.

A description should be provided for each declared variable.

// bad
variable "vpc_id" {}

// good
variable "vpc_id" {
  description = "The VPC this security group will go in"
}

Outputs

Outputs should be provided in an outputs.tf file at the root of your project.

Comments

Only comment what is necessary.

Single line comments: # or //.

Multi-line comments: /* followed by */.

About

Terraform style guide

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published