azureazure-storageazure-virtual-machineterraformazure-managed-disk

Terraform Backend in azure with managed disks


We are migrating from unmanaged to managed disks in Azure. Currently our backend.tf definition is as follows

terraform {
  backend "azure" {
    storage_account_name = "foo"
    container_name = "foo-container"
    key = "foo.tfstate"
  }
}

With managed disks you don't have reference to storage account as it is managed by Azure. What does this mean for backend.tf. Do we just remove storage account and container? Do we need to add some flag to identify backend storage as managed? Google search is not producing required answers, hence reaching out here.

Thanks


Solution

  • With managed disks you don't have reference to storage account as it is managed by Azure. What does this mean for backend.tf.

    It means you could not use backend "azure", Azure managed disk does not support this.

    Please refer to this official document.Stores the state as a given key in a given blob container on Microsoft Azure Storage.

    Creating managed disk with terraform you could check this link.

    resource "azurerm_managed_disk" "test" {
      name = "acctestmd"
      location = "West US 2"
      resource_group_name = "${azurerm_resource_group.test.name}"
      storage_account_type = "Standard_LRS"
      create_option = "Empty"
      disk_size_gb = "1"
    
      tags {
        environment = "staging"
      }