Using Terraform Cloud store the state files in Azure storage account

263 views Asked by At

Terraform Cloud store the state files in Azure storage account, When using Terraform Cloud, the default behaviour is indeed to store the state files within Terraform Cloud itself. However, we can override this behaviour by explicitly configuring a remote backend in my Terraform configuration files is that possible? I have tried to create the remote backend but it is not storing the file in storage account. Assist me to resolve this issue, Thanks in Advance!!

terraform {
  backend "azurerm" {
    resource_group_name  = "Azure"
    storage_account_name = "azuredevopsdev"
    container_name       = "terraformcloud"
    key                  = "resourcegroup.tfstate"
  }
}
1

There are 1 answers

1
Vinay B On

I tried using Terraform Cloud to store the state files in the Azure storage account while provisioning the resource and I was able to achieve the requirement.

To achieve this, you need to use a remote backend configuration in your Terraform files, as you've started doing.

However, if the state files are not being stored in the Azure storage account as expected, there might be issues with either the configuration or with permissions/access to the Azure storage account.

Here for demo purposes, I was trying to provision the resource group using Azure backend configuration which ended by storing the state file in the remote repository location i.e., in the storage account container we are looking for.

My demo terraform configuration:

provider "azurerm" {
    features {}
}

terraform {
  backend "azurerm" {
    resource_group_name  = "sakavya"
    storage_account_name = "demovksb"
    container_name       = "demovkcon"
    key                  = "resourcegroup.tfstate"
  }
}


resource "azurerm_resource_group" "example" {
  name     = "demo-rgvksb"
  location = "east us"
}

Output:

enter image description here

enter image description here

Note: Make sure you are using the same user or SP that was used to create the storage account for the configuration in order to overcome the permission issues while accessing the storage account to store state files remotely. If not try to get relevant permissions on the storage account to have full access.