profile for CodeWizard at Stack Overflow, Q&A for professional and enthusiast programmersVisitor BadgeLinkedin BadgeGmail BadgeOutlook Badge


Terraform Hands-on Repository

  • A collection of Hands-on labs for Terraform.
  • Each lab is a standalone lab and does not require to complete the previous labs.

Open in Cloud Shell

CTRL + click to open in new window


Pre-Requirements

This tutorial will walk you using terraform locally without any requirements for any cloud provider.
If you are using GCP all the tools are pre-installed

Terraform Kubernetes Minikube Helm kubectl
Tool Comments
K8S An existing cluster or any other local tool as described here
kubectl The Kubernetes command-line tool, kubectl
minikube Local cluster for running the hands on labs
Helm Some of the demos will require helm charts installed
Terraform This is what this tutorial is about ...

What is Terraform?

  • IAC - Infrastructure As Code
  • Open Source developed by HashiCorp
  • Declarative language - Define what you want and terraform will "get" there, terraform will figure out how to create what you wish.
  • Terraform is mainly for Infrastructure (IAC)
  • Terraform is based upon modules

Terraform Key Features

  • Infrastructure as a Code

    • Infrastructure is described using a high-level configuration syntax with HCL files.
    • Due to the fact that HCL are text files they can be stores in SCM (GIT for example) in a branch level, this ability allow to share, reuse, versioned and more.
  • Execution Plans

    • terraform plan generates an execution plan (JSON file).
    • Since this a text file (JSON) as mentioned above it can be stored in SCM (GIT for example) and can versioned, shared and more.
    • The execution plan calculate the "difference" between the current state to the desired state.
    • The plan describe exactly what Terraform will change and in what order which make it clear what will happen.
  • Resource Graph

    • Terraform builds a graph of all your resources.

    • Terraform try to execute the required changes in parallel of any non-dependent resources.

    • terraform graph generate a DOT (DOT is a graph description language) files which can be converted to svg images for example.

    • # Generate a graph based upon the execution plan
      # require dot to be installed,
      
      ### MacOs
          brew install graphviz
      ### Linux
          sudo apt-get install graphviz
      
      terraform graph | dot -Tsvg > graph.svg
      
  • Automation

    • Terraform as IAC (Infrastructure as code) tool, and as such it designed for making automated changes or with a minimal human interaction.
    • Terraform support using templates for re-use code. In this way we it support multiple environments, providers by writing a simple syntax.

Terraform Architecture

  • Terraform is build upon 2 main components:
    • Core
    • State
  • User write the desired code, terraform calculate the desired result and execute it using the selected provider.
  • In the following labs we will learn how to work with Terraform

  • List of the labs in this repository:

📗 00-Setup

CLI commands

📗 01-init
📗 02-get
📗 03-validate
📗 04-plan
📗 05-apply
📗 06-destroy
📗 07-refresh
📗 09-import
📗 10-state
📗 11-workspace
📗 12-graph
📗 02-Variables
📗 03-Getting-Started-Kubernetes
📗 04-Getting-Started-Helm-Chart


📗 00.00-Setup

📗 01.00-CLI-Commands

📗 01.01-init

📗 01.02-get

📗 01.03-validate

📗 01.04-plan

📗 01.05-apply

📗 01.06-destroy

📗 01.07-refresh

©CodeWizard LTD