Search code examples
azureterraformterraform-provider-azureazure-rm

Create incremental Azure Managed Disk Snapshots using Terraform


I'm using PremiumV2_LRS managed disks in Terraform, along with azurerm provider on its latest version (3.48.0).

These kind of disks only support incremental snapshots. I can create snapshots using the az command line tool with no issues (I can create snapshots too using the Azure Portal):

$ az snapshot create \
  --name metadata-disk-snapshot \
  --resource-group storage-resources \
  --source "/subscriptions/0000(...)/disks/metadata-disk" \
  --incremental true

However, using Terraform I can't create these kind of snapshots. This is how I have defined both the disk and the snapshot:

resource "azurerm_managed_disk" "storage_metadata_disk" {
  name                 = "metadata-disk"
  location             = azurerm_resource_group.storage_resource_group.location
  resource_group_name  = azurerm_resource_group.storage_resource_group.name
  zone                 = var.disks_configuration.azure_availability_zone
  storage_account_type = "PremiumV2_LRS"
  create_option        = "Empty"
  disk_size_gb         = var.disks_configuration.metadata_disk.size_gb
  disk_iops_read_write = var.disks_configuration.metadata_disk.iops
  disk_mbps_read_write = var.disks_configuration.metadata_disk.mbps
}

resource "azurerm_snapshot" "storage_metadata_disk_snapshot" {
  name                = "metadata-disk-snapshot"
  location            = azurerm_resource_group.storage_resource_group.location
  resource_group_name = azurerm_resource_group.storage_resource_group.name
  source_uri          = azurerm_managed_disk.storage_metadata_disk.id
  create_option       = "Import"
}

azurerm_snapshot.create_option only accepts Import and Copy, and neither will work. "Copy" seems to mean "copy an already existing snapshot", and "Import" could mean "incremental", but that does not seem to be the case.

However, both these options fail. When using "Copy" the error is clear - only incremental:

**Error: creating/updating Snapshot (Subscription: "(...)" Resource Group Name: "storage-resources" Snapshot Name: "metadata-disk-snapshot"): performing CreateOrUpdate: snapshots.SnapshotsClient#CreateOrUpdate: Failure sending request: StatusCode=0 -- Original Error: Code="OperationNotAllowed" Message="Only incremental snapshots are supported for disks of Sku PremiumV2\_LRS."**
with module.(...)\_metadata\_disk\_snapshot
on .terraform/modules/(...)/main.tf line 30, in resource "azurerm\_snapshot" "storage\_metadata\_disk\_snapshot":

And when using "Import" (the only other valid option):

**Error: creating/updating Snapshot (Subscription: "(...)" Resource Group Name: "storage-resources" Snapshot Name: "metadata-disk-snapshot"): performing CreateOrUpdate: snapshots.SnapshotsClient#CreateOrUpdate: Failure sending request: StatusCode=0 -- Original Error: Code="InvalidParameter" Message="Uri not of expected kind" Target="sourceUri"**
with module.(...)\_metadata\_disk\_snapshot
on .terraform/modules/(...)/main.tf line 30, in resource "azurerm\_snapshot" "storage\_metadata\_disk\_snapshot":

If I try to use an undocumented option (such as a made up value) the error message is that it expects create_option to be either Copy or Import.

Any suggestions?


Solution

  • It's not currently supported. I came here to suggest you open an issue in the Terraform provider's github repo but you already did that. Good job!

    https://github.com/hashicorp/terraform-provider-azurerm/issues/21099