Skip to content

This is to show demo about how to use azure backend to store terraform state

Notifications You must be signed in to change notification settings

santosh0787/terraform_az_backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Terraform with Azure Backend

This is a demo to show how to save terraform state in Azure Blob storage.

Procedure

  1. In azure portal, create a storage account. example "testsantosh"
  2. Create container called "tfstate".
  3. Create a main.tf file which is there in git repo and keep below contents:

main.tf

terraform {
  backend "azurerm" {
  }
}

provider "azurerm" {
  # whilst the `version` attribute is optional, we recommend pinning to a given version of the Provider
  version = "=2.0.0"
  subscription_id = "xxxxxxxxxxxxx"
  tenant_id = "xxxxxxxxxxxxxxxxxxx"
  features {}
}
  • In above file first block, you are specifying that terraform should use azure backend.
  • In second bloack, you specify Basic azure subscription id and tenant id.
  1. variables.tf and as_create.tf are basic terraform files to create a availabilty set.
  2. backend.tfvars has important properties.
resource_group_name="RG_NAME"
storage_account_name="testterraform"
container_name="tfstate"
access_key="xxxxxxx"
key="test.tfstate"

In above properties,

  • access_key is the storage account key. You can find it in "testterraform" storage account -> Settings -> access keys
  • key is the file name of terraform statefile.

after having this files ready, you can now execute:

    terraform init -backend-config=backend.tfvars
    terraform plan
    terraform apply

You can see statefile will acquire-release lock during plan and apply procedures. This helps to avoid corrupt if multiple members want to access/modify/plan/apply same terraform configuration.

  1. If you don't want to save access_key in a file, you can pass as ENV variable.

ARM_ACCESS_KEY=xxxxxxxxxxxxxxxxxxx

About

This is to show demo about how to use azure backend to store terraform state

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages