Terraform

  • Terraform
    • Introduction to Terraform
    • Getting Started
    • Terraform Components
    • Terraform Execution Steps
  • Terraform (advanced)
    • Terraform Components
    • Terraform Executable
    • Terraform Files
    • Configuration Files
    • Terraform File Structure
      • Variables
      • Providers
      • Output
      • Resources
    • Terraform Syntax
      • Blocks
    • Terraform Plugins
      • Providers
    • Terraform State
      • Update Configuration
  • Terraform File Structure
    • File Hierarchy and Structure

Introduction to Terraform

Terraform is a tool from HashiCorp to manage infrastructure as code.

It supports the concept of providers to integrate with different platforms like Azure, AWS, GCP, Kubernetes and more. Supporting different providers make Terraform very popular and powerful.

Getting Started

Automating infrastructure deployment.

Key Concepts:

  • Provisioning Resources
  • Planning Updates
  • Using Source Control
  • Reusing Templates

Terraform rule: Make all changes in Terraform.

Hello World

The following sample is a very simple configuration to showcase the deployment of …

variable "subscription_id" {}
variable "tenant_id" {}

variable "location" {
   default = "west"
}

## sample ...

Structure of a Terraform file

  • Variables
  • Providers
  • Resources
  • Outputs

Terraform Components

Terraform consists of the following components:

  • Terraform executable is a single executable written in Go (no installation or dependencies needed), available on multiple operating systems
  • Terraform files contains the configuration and the file have a .tf extension. If a directory contains multiple Terraform files, they will be sticked together.
  • Terraform plugins like providers for AWS, Azure, etc.
  • Terraform state, is a file with the current state

Terraform Execution Steps

Cycle and steps in a Terraform deployment

  1. terraform init will initialize by looking at the configuration files, encounters the providers and downloads the plugins like Azure provider.
  2. terraform plan will look at the configuration files in the current working directory and loads the variables in this directory. It will look at the existing environment and compares it with the desired configuration and then figures out what to do.
  3. terraform apply will deploy the environment using the plan and then store the state in the terraform state file.
  4. terraform destroy will delete all resources which are in the configuration.

    Resume / recap

    So Terraform can …