Terraform Tutorial

This is a short tutorial on using Terraform with AWS. It assumes some basic knowledge of Terraform.

Requirements

You'll need an [Amazon Web Services account][https:/aws.amazon.com/), the AWS CLI, Git, and Terraform.

You'll also need something to edit Terraform files, preferably with some syntax highlighting, etc. Some plugins / modes / extensions for common editors:

Tools Setup

You'll need to install some tools before starting this tutorial:

  • aws - the Amazon command line client is useful for configuring AWS profiles, credentials, and options
  • git - version (source code) tool
  • jq - command line JSON tool
  • terraform - command line tool for managing infrastructure resources

Mac Setup

  • Install Homebrew
  • Use Homebrew to install Terraform, the AWS CLI, jq, and a newer version of git
% brew update
% brew install awscli git jq terraform

Linux Setup

  1. Install curl, git, groff, jq, pip3 (Python3), and unzip

    • APT based

      % sudo apt-get update
      % sudo apt-get install curl git groff jq python3-pip unzip
    • YUM based

      % sudo yum update
      % sudo yum install curl git groff-base jq python3-pip unzip
    • Alpine

      % sudo apk update
      % sudo apk add curl git groff jq python3 unzip
  2. Install the AWS CLI

    % sudo pip3 install awscli
  3. Install Terraform

    % cd /usr/local/bin
    % curl -so /tmp/terraform.zip https://releases.hashicorp.com/terraform/0.12.26/terraform_0.12.26_linux_amd64.zip
    % sudo unzip /tmp/terraform.zip
    % rm /tmp/terraform.zip

Windows Setup

I rarely use Windows, but here are some starting points

AWS Setup

You should create a Terraform IAM User in your AWS account, and grant that user full admin rights. This video shows the steps to take in the AWS Console to create a new IAM user with credentials and the correct policy:

  1. Create new IAM user (called terraform)
  2. Attach the AdministratorAccess policy to the user
  3. Create and download credentials for the user

Watch the Video