Infrastructure as Code example

IoC examples using Azure

View on GitHub
Home Github basics part 1 Terraform basics part 1 Terraform Examples Github collaboration

Terraform state

Introduction

Terraform must store state about your managed infrastructure and configuration. This state is used by Terraform to map real world resources to your configuration, keep track of metadata, and to improve performance for large infrastructures.

By default the state is stored locally in a file named terraform.tfstate. We want to store the state in a container in Azure.

Ref: https://www.terraform.io/docs/state

Adding our state configuration to Terraform

This configuration states that we would like to store our state in Azure

Create a file: terraformstate.tf using this template

#Configure the state location
terraform {
  backend "azurerm" {
    resource_group_name   = "****************"
    storage_account_name  = "****************"
    container_name        = "****************"
    key                   = "terraform.tfstate"
  }
}
  1. Goto Azure portal
  2. Navigate to your Resource group and fill in: resource_group_name
  3. Navigate to your Storage account and fill in: storage_account_name
  4. Navigate to your Container and fill in: container_name