learn-terraform

Course outlines for learning terraform.

View the Project on GitHub robertdebock/learn-terraform

Store remote state

expected time requirements
60 minutes A computer with Terraform installed.

Goal: Learn how to store remote state:

Explanation

You’ve learned to work with a local state file so far. When you work with multiple people, you need to share the same state. If you do not share the same state, you can step on each-others toes when applying code.

With remote state, you basically do two things:

  1. The state is saved centrally.
  2. Locking happens centrally.

Howto

For “generic” use of cloud providers you can follow:

For our environment, we’ll store the state and lock in a azure container.

To store the remote state in Azure, this can be used: (Change MY_STATE_NAME to something like robertdebock.

Change the terraform parameter in main.tf to this.

terraform {
  backend "azurerm" {
  resource_group_name  = "rg-terraform-cmn-sbx"
  storage_account_name = "stterraformcmnsbx"
  container_name       = "c-terraform"
  key                  = "rg-MY_STATE_NAME-sbx.tfstate"
  }
  required_providers {
    azurerm = {
      source = "hashicorp/azurerm"
      version = ">= 2.26"
    }
  }
}

Assignment

Questions:

  1. What is so critical about the state?
  2. Does the state contain sensitive information?
  3. What have you solved now that the state is remote?