What the Hack: Infrastructure as Code with Terraform

Introduction

DevOps is a journey not a destination. Implementing Infrastructure-as-Code is one of the first steps you will take on your DevOps journey!

When implementing an application environment in the cloud, it is important to have a repeatable way to deploy the underlying infrastructure components as well as your software into the target environment. This includes resources such as:

The best way to make deployments repeatable is to define them with code, hence the term “Infrastructure as Code” (aka IAC). There are multiple technologies that enable you to define your IaC. Some of these include:

Terraform is a tool (templating language) for building, changing, and versioning infrastructure safely and efficiently. Using Terraform, you can automate the tasks of building, changing and de-provisioning the infrastructure

This hack is focused on using Terraform to implement your IaC. It does not mean this is the only way to implement IaC. It is just one way amongst many. If you want to learn how to do IaC in Azure with other technologies, try one of our other IaC hacks for ARM Templates or Ansible.

Learning Objectives

This hack will help you learn:

Challenges

  1. Get your machine ready
    • Configure Terraform on Linux subsystem, credentials
  2. “Hello World” Terraform
    • Create an Azure resource group using Terraform
  3. Deploy a Virtual Network
    • Learn how to find Terraform HCL syntax to deploy an Azure resource
  4. Open Some Ports
    • Learn about variables, dependencies, idempotency
  5. Create a Linux Virtual Machine
    • Learn what an Azure Virtual Machine is composed of
  6. Use Packer to Create a Linux image with NGINX installed
    • Learn about custom build images with Packer

Prerequisites

Repository Contents

Contributors