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
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
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
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(
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
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
Parameters
-
create_option
required - string -
disk_size_gb
optional computed - number -
id
optional computed - string -
location
required - string -
name
required - string -
resource_group_name
required - string -
source_resource_id
optional - string -
source_uri
optional - string -
storage_account_id
optional - string -
tags
optional - map from string to string -
encryption_settings
list block-
enabled
required - bool -
disk_encryption_key
list block-
secret_url
required - string -
source_vault_id
required - string
-
-
key_encryption_key
list block-
key_url
required - string -
source_vault_id
required - string
-
-
-
timeouts
single block
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.
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.
azurerm_managed_disk
Ensure to enable the encryption on managed disks
It is better to enable the encryption on managed disks.
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.
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
"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",
"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",
"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",
"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",
"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",
"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",
"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"
},
{
"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"
},
{
"type": "Microsoft.Compute/snapshots",
"name": "[parameters('OS-Snapshot-name')]",
"location": "[parameters('location')]",
"sku": {
"name": "[parameters('accountType')]"
},
"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.