TerribleDev
TerribleDev

Reputation: 2245

Terraform remote state azure

I have worked with terraform before, where terraform can place the tfstate files in S3. Does terraform also support azure blob storage as a backend? What would be the commands to set the backend to be azure blob storage?

Upvotes: 0

Views: 548

Answers (2)

cabreracanal
cabreracanal

Reputation: 934

The question asks for some commands, so I'm adding a little more detail in case anyone needs it. I'm using Terraform v0.12.24 and azurerm provider v2.6.0. You need two things:

  1. Create a storage account (general purpose v2) and a container for storing your states.
  2. Configure your environment and your main.tf

As for the second point, your terraform block in main.tf should contain a "azurerm" backend:

terraform {
  required_version = "=0.12.24"
  backend "azurerm" {
    storage_account_name = "abcd1234"
    container_name       = "tfstatecontainer"
    key                  = "example.prod.terraform.tfstate"
}

provider "azurerm" {
  version = "=2.6.0"
  features {}
  subscription_id = var.subscription_id
}

Before calling to plan or apply, init the ARM_ACCESS_KEY variable with a bash export:

export ARM_ACCESS_KEY=<storage access key>

Finally, run the init command:

terraform init

Now, if you run terraform plan you will see the tfstate created in the container. Azure has a file locking feature built in, in case anyone tries to update the state file at the same time.

Upvotes: 0

ydaetskcoR
ydaetskcoR

Reputation: 56997

As of Terraform 0.7 (not currently released but you can compile from source) support for Azure blob storage has been added.

Upvotes: 1

Related Questions