BossaBox

This is the playbook for engineering-playbook

Terraform Code Reviews

Style Guide

Developers should follow the terraform style guide.

Projects should check Terraform scripts with automated tools.

Code Analysis / Linting

TFLint

TFLint is a Terraform linter focused on possible errors, best practices, etc. Once TFLint installed in the environment, it can be invoked using the VS Code terraform extension.

VS Code Extensions

The following VS Code extensions are widely used.

Terraform extension

This extension provides syntax highlighting, linting, formatting and validation capabilities.

Azure Terraform extension

This extension provides Terraform command support, resource graph visualization and CloudShell integration inside VS Code.

Build Validation

Ensure you enforce the style guides during build. The following example script can be used to install terraform, and a linter that then checks for formatting and common errors.

#! /bin/bash
set -e

SCRIPT_DIR=$(dirname "$BASH_SOURCE")
cd "$SCRIPT_DIR"

TF_VERSION=0.12.4
TF_LINT_VERSION=0.9.1

echo -e "\n\n>>> Installing Terraform 0.12"
# Install terraform tooling for linting terraform
wget -q https://releases.hashicorp.com/terraform/${TF_VERSION}/terraform_${TF_VERSION}_linux_amd64.zip -O /tmp/terraform.zip
sudo unzip -q -o -d /usr/local/bin/ /tmp/terraform.zip

echo ""
echo -e "\n\n>>> Install tflint (3rd party)"
wget -q https://github.com/wata727/tflint/releases/download/v${TF_LINT_VERSION}/tflint_linux_amd64.zip -O /tmp/tflint.zip
sudo unzip -q -o -d /usr/local/bin/ /tmp/tflint.zip

echo -e "\n\n>>> Terraform version"
terraform -version

echo -e "\n\n>>> Terraform Format (if this fails use 'terraform fmt -recursive' command to resolve"
terraform fmt -recursive -diff -check

echo -e "\n\n>>> tflint"
tflint

echo -e "\n\n>>> Terraform init"
terraform init

echo -e "\n\n>>> Terraform validate"
terraform validate

Code Review Checklist

In addition to the Code Review Checklist you should also look for these Terraform specific code review items

Providers

Repository Organization

Terraform state

Variables

Testing

Naming and code structure

General recommendations