Skip to content

azurermSnapshot

Manages a Disk Snapshot.

Example Usage

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as azurerm from "./.gen/providers/azurerm";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: azurerm.
For a more precise conversion please use the --provider flag in convert.*/
const azurermResourceGroupExample = new azurerm.resourceGroup.ResourceGroup(
  this,
  "example",
  {
    location: "West Europe",
    name: "snapshot-rg",
  }
);
const azurermManagedDiskExample = new azurerm.managedDisk.ManagedDisk(
  this,
  "example_1",
  {
    create_option: "Empty",
    disk_size_gb: "10",
    location: azurermResourceGroupExample.location,
    name: "managed-disk",
    resource_group_name: azurermResourceGroupExample.name,
    storage_account_type: "Standard_LRS",
  }
);
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermManagedDiskExample.overrideLogicalId("example");
const azurermSnapshotExample = new azurerm.snapshot.Snapshot(
  this,
  "example_2",
  {
    create_option: "Copy",
    location: azurermResourceGroupExample.location,
    name: "snapshot",
    resource_group_name: azurermResourceGroupExample.name,
    source_uri: azurermManagedDiskExample.id,
  }
);
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermSnapshotExample.overrideLogicalId("example");

Argument Reference

The following arguments are supported:

  • name - (Required) Specifies the name of the Snapshot resource. Changing this forces a new resource to be created.

  • resourceGroupName - (Required) The name of the resource group in which to create the Snapshot. Changing this forces a new resource to be created.

  • location - (Required) Specifies the supported Azure location where the resource exists. Changing this forces a new resource to be created.

  • createOption - (Required) Indicates how the snapshot is to be created. Possible values are copy or import.

\~> Note: One of sourceUri, sourceResourceId or storageAccountId must be specified.

  • sourceUri - (Optional) Specifies the URI to a Managed or Unmanaged Disk. Changing this forces a new resource to be created.

  • sourceResourceId - (Optional) Specifies a reference to an existing snapshot, when createOption is copy. Changing this forces a new resource to be created.

  • storageAccountId - (Optional) Specifies the ID of an storage account. Used with sourceUri to allow authorization during import of unmanaged blobs from a different subscription. Changing this forces a new resource to be created.

  • diskSizeGb - (Optional) The size of the Snapshotted Disk in GB.

  • encryptionSettings - (Optional) A encryptionSettings block as defined below.

\~> NOTE: Removing encryptionSettings forces a new resource to be created.

  • tags - (Optional) A mapping of tags to assign to the resource.

The encryptionSettings block supports:

  • diskEncryptionKey - (Optional) A diskEncryptionKey block as defined below.

  • keyEncryptionKey - (Optional) A keyEncryptionKey block as defined below.


The diskEncryptionKey block supports:

  • secretUrl - (Required) The URL to the Key Vault Secret used as the Disk Encryption Key. This can be found as id on the azurermKeyVaultSecret resource.

  • sourceVaultId - (Required) The ID of the source Key Vault. This can be found as id on the azurermKeyVault resource.


The keyEncryptionKey block supports:

  • keyUrl - (Required) The URL to the Key Vault Key used as the Key Encryption Key. This can be found as id on the azurermKeyVaultKey resource.

  • sourceVaultId - (Required) The ID of the source Key Vault. This can be found as id on the azurermKeyVault resource.

Attributes Reference

The following attributes are exported:

  • id - The Snapshot ID.

  • diskSizeGb - (Optional) The Size of the Snapshotted Disk in GB.

  • trustedLaunchEnabled - Whether Trusted Launch is enabled for the Snapshot.

Timeouts

The timeouts block allows you to specify timeouts for certain actions:

  • create - (Defaults to 30 minutes) Used when creating the Snapshot.
  • update - (Defaults to 30 minutes) Used when updating the Snapshot.
  • read - (Defaults to 5 minutes) Used when retrieving the Snapshot.
  • delete - (Defaults to 30 minutes) Used when deleting the Snapshot.

Import

Snapshots can be imported using the resourceId, e.g.

terraform import azurerm_snapshot.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/Microsoft.Compute/snapshots/snapshot1