Search code examples
azureterraformterraform-provider-azure

How to config backups of Azure Managed Disks from Terraform?


I'd like to create a backup from an Azure managed disk, as this article says, but with terraform.

I can create the managed disk as:

resource "azurerm_managed_disk" "mongodb_disk" {
  name = "${var.env_name}-mongodb-disk"
  location = var.resource_group.location
  resource_group_name = var.resource_group.name
  create_option = "Empty"
  storage_account_type = "Premium_LRS"
  disk_size_gb = var.mongo_db_disk_size_in_gb
}

But I'm unable to find the following resources:

  • backup vault
  • the backup policy in the vault
  • the backup itself in the vault

Could you help me with the correct terraform resources, to create the backup? Or is there an example anywhere, how to create a scheduled backup of an Azure Managed Disk?

Thanks,


Solution

  • EDIT: Just realised that Azure Backup Vault is not yet supported in Terraform, you can upvote the issue.

    For VMs backups it's just Azure Recovery Services Vault. A workaround could be for you to use an external terraform object that will run either a PowerShell or Bash script (using Az Cli), to create the backup. It's not 100% IaC but better than nothing.