Azure Compute Snapshot

This page shows how to write Terraform and Azure Resource Manager for Compute Snapshot and write them securely.

azurerm_snapshot (Terraform)

The Snapshot in Compute can be configured in Terraform with the resource name azurerm_snapshot. The following sections describe 5 examples of how to use the resource and its parameters.

Example Usage from GitHub

main.tf#L1
resource "azurerm_snapshot" "example" {
  name                = var.name
  location            = module.resource_group.azurerm_resource_group.example.location
  resource_group_name = module.resource_group.azurerm_resource_group.example.name
  create_option       = var.create_option
  source_uri          = module.managed_disk.azurerm_managed_disk.example.id
disk.tf#L3
resource "azurerm_snapshot" "tf" {
  name                = "snapshotpspl"
  location            = data.azurerm_resource_group.tfm.location
  resource_group_name = data.azurerm_resource_group.tfm.name
  create_option       = "Copy"
  source_uri          = data.azurerm_managed_disk.tfm.id
snapshot.tf#L1
resource "azurerm_snapshot" "snapshot" {
    create_option       = "Copy"
    disk_size_gb        = data.azurerm_managed_disk.source-disk.disk_size_gb
    # encryption_settings = data.azurerm_managed_disk.source-disk.encryption_settings
    location            = var.destination-disk.location
    name                = format(
main.tf#L7
resource "azurerm_snapshot" "this" {
  create_option       = var.create_option
  disk_size_gb        = var.disk_size_gb
  location            = var.location
  name                = var.name
  resource_group_name = var.resource_group_name
main.tf#L7
resource "azurerm_snapshot" "this" {
  create_option       = var.create_option
  disk_size_gb        = var.disk_size_gb
  location            = var.location
  name                = var.name
  resource_group_name = var.resource_group_name

Review your Terraform file for Azure best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).

Parameters

Explanation in Terraform Registry

Manages a Disk Snapshot.

Tips: Best Practices for The Other Azure Compute Resources

In addition to the azurerm_linux_virtual_machine, Azure Compute has the other resources that should be configured for security reasons. Please check some examples of those resources and precautions.

risk-label

azurerm_linux_virtual_machine

Ensure to use SSH authentication for virtual machines

It is better to use SSH authentication for virtual machines instead of password authentication to enforce more secure ways.

risk-label

azurerm_managed_disk

Ensure to enable the encryption on managed disks

It is better to enable the encryption on managed disks.

risk-label

azurerm_virtual_machine

Ensure to use SSH authentication for virtual machines

It is better to use SSH authentication for virtual machines instead of password authentication to enforce more secure ways.

Review your Azure Compute settings

In addition to the above, there are other security points you should be aware of making sure that your .tf files are protected in Shisho Cloud.

Microsoft.Compute/snapshots (Azure Resource Manager)

The snapshots in Microsoft.Compute can be configured in Azure Resource Manager with the resource name Microsoft.Compute/snapshots. The following sections describe how to use the resource and its parameters.

Example Usage from GitHub

_subscriptions_99999999_providers_Microsoft_Compute_snapshots.json#L15
      "type": "Microsoft.Compute/snapshots",
      "location": "eastus",
      "tags": {
        "test_snap": "test"
      },
      "id": "/subscriptions/99999999-9999-9999-9999-999999999999/resourceGroups/000000/providers/Microsoft.Compute/snapshots/test-snap-1",
_subscriptions_99999999_providers_Microsoft_Compute_snapshots.json#L15
      "type": "Microsoft.Compute/snapshots",
      "location": "eastus",
      "tags": {
        "test_snap": "test"
      },
      "id": "/subscriptions/99999999-9999-9999-9999-999999999999/resourceGroups/000000/providers/Microsoft.Compute/snapshots/test-snap-1",
_subscriptions_99999999_providers_Microsoft_Compute_snapshots.json#L15
      "type": "Microsoft.Compute/snapshots",
      "location": "eastus",
      "tags": {
        "test_snap": "test"
      },
      "id": "/subscriptions/99999999-9999-9999-9999-999999999999/resourceGroups/000000/providers/Microsoft.Compute/snapshots/test-snap-1",
_subscriptions_99999999_providers_Microsoft_Compute_snapshots.json#L15
      "type": "Microsoft.Compute/snapshots",
      "location": "eastus",
      "tags": {
        "test_snap": "test"
      },
      "id": "/subscriptions/99999999-9999-9999-9999-999999999999/resourceGroups/000000/providers/Microsoft.Compute/snapshots/test-snap-1",
_subscriptions_99999999_providers_Microsoft_Compute_snapshots.json#L15
      "type": "Microsoft.Compute/snapshots",
      "location": "eastus",
      "tags": {
        "test_snap": "test"
      },
      "id": "/subscriptions/99999999-9999-9999-9999-999999999999/resourceGroups/000000/providers/Microsoft.Compute/snapshots/test-snap-1",
_subscriptions_99999999_providers_Microsoft_Compute_snapshots.json#L15
      "type": "Microsoft.Compute/snapshots",
      "location": "eastus",
      "tags": {
        "test_snap": "test"
      },
      "id": "/subscriptions/99999999-9999-9999-9999-999999999999/resourceGroups/000000/providers/Microsoft.Compute/snapshots/test-snap-1",
_subscriptions_99999999_resourceGroups_111111_providers_Microsoft_Compute_snapshots.json#L15
      "type": "Microsoft.Compute/snapshots",
      "location": "eastus",
      "id": "/subscriptions/99999999-9999-9999-9999-999999999999/resourceGroups/111111/providers/Microsoft.Compute/snapshots/test-snap-3",
      "name": "test-snap-3"
    },
    {
_subscriptions_99999999_resourceGroups_111111_providers_Microsoft_Compute_snapshots.json#L15
      "type": "Microsoft.Compute/snapshots",
      "location": "eastus",
      "id": "/subscriptions/99999999-9999-9999-9999-999999999999/resourceGroups/111111/providers/Microsoft.Compute/snapshots/test-snap-3",
      "name": "test-snap-3"
    },
    {
Snapshot-from-Disk-VM.json#L66
      "type": "Microsoft.Compute/snapshots",
      "name": "[parameters('OS-Snapshot-name')]",
      "location": "[parameters('location')]",
      "sku": {
        "name": "[parameters('accountType')]"
      },
_subscriptions_99999999_resourceGroups_111111_providers_Microsoft_Compute_snapshots.json#L15
      "type": "Microsoft.Compute/snapshots",
      "location": "eastus",
      "id": "/subscriptions/99999999-9999-9999-9999-999999999999/resourceGroups/111111/providers/Microsoft.Compute/snapshots/test-snap-3",
      "name": "test-snap-3"
    },
    {

Frequently asked questions

What is Azure Compute Snapshot?

Azure Compute Snapshot is a resource for Compute of Microsoft Azure. Settings can be wrote in Terraform.

Where can I find the example code for the Azure Compute Snapshot?

For Terraform, the VentsislavDinev/en_sample, FourTimes/azure-vm-single-disk-snapshot-creation and davidjsanders/tf-library source code examples are useful. See the Terraform Example section for further details.

For Azure Resource Manager, the apache/libcloud, chenjiang1985/libcloud and strcloud/libcloud_custom source code examples are useful. See the Azure Resource Manager Example section for further details.