Azure Compute Disk Encryption Set

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

azurerm_disk_encryption_set (Terraform)

The Disk Encryption Set in Compute can be configured in Terraform with the resource name azurerm_disk_encryption_set. The following sections describe 10 examples of how to use the resource and its parameters.

Example Usage from GitHub

main.tf#L1
resource "azurerm_disk_encryption_set" "disk_encryption_set" {
  count               = length(var.disk_encryption_set)
  name                = lookup(var.disk_encryption_set[count.index], "name")
  resource_group_name = element(var.resource_group_name, lookup(var.disk_encryption_set[count.index], "resource_group_id"))
  location            = element(var.location, lookup(var.disk_encryption_set[count.index], "location_id"))
  key_vault_key_id    = element(var.key_vault_key_id, lookup(var.disk_encryption_set[count.index], "key_vault_key_id"))
disk_encryption_set.tf#L1
resource "azurerm_disk_encryption_set" "encryption_set" {
  name                = var.settings.name
  resource_group_name = var.resource_groups[var.settings.resource_group_key].name
  location            = lookup(var.settings, "region", null) == null ? var.resource_groups[var.settings.resource_group_key].location : var.global_settings.regions[var.settings.region]
  key_vault_key_id    = var.key_vault_key_ids[var.settings.key_vault_key_key].id

main.tf#L1
resource "azurerm_disk_encryption_set" "example" {
  name                = var.name
  resource_group_name = module.resource_group.azurerm_resource_group.example.name
  location            = module.resource_group.azurerm_resource_group.example.location
  key_vault_key_id    = module.key_vault_key.azurerm_key_vault_key.example.example.id

des.tf#L2
resource "azurerm_disk_encryption_set" "des" {
  name                        = "des"
  location                    = azurerm_resource_group.rg.location
  resource_group_name         = azurerm_resource_group.rg.name
  key_vault_key_id            = azurerm_key_vault_key.encryption_key.id

disk_encryption_set.tf#L1
resource "azurerm_disk_encryption_set" "encryption_set" {
  name                = var.settings.name
  resource_group_name = var.resource_groups[var.settings.resource_group_key].name
  location            = lookup(var.settings, "region", null) == null ? var.resource_groups[var.settings.resource_group_key].location : var.global_settings.regions[var.settings.region]
  key_vault_key_id    = var.key_vault_key_ids[var.settings.key_vault_key_key].id

disk_encryption_set.tf#L1
resource "azurerm_disk_encryption_set" "encryption_set" {
  name                = var.settings.name
  resource_group_name = var.resource_groups[var.settings.resource_group_key].name
  location            = lookup(var.settings, "region", null) == null ? var.resource_groups[var.settings.resource_group_key].location : var.global_settings.regions[var.settings.region]
  key_vault_key_id    = var.key_vault_key_ids[var.settings.key_vault_key_key].id

main.tf#L7
resource "azurerm_disk_encryption_set" "this" {
  key_vault_key_id    = var.key_vault_key_id
  location            = var.location
  name                = var.name
  resource_group_name = var.resource_group_name
  tags                = var.tags
main.tf#L56
resource "azurerm_disk_encryption_set" "des" {
    name                = var.des_name
    resource_group_name = var.resource_group_name
    location            = var.location
    key_vault_key_id    = azurerm_key_vault_key.des_key.id

main.tf#L57
resource "azurerm_disk_encryption_set" "des" {
    name                = var.des_name
    resource_group_name = var.resource_group_name
    location            = var.location
    key_vault_key_id    = azurerm_key_vault_key.des_key.id

main.tf#L20
resource "azurerm_disk_encryption_set" "des" {
  name                = var.des_name
  resource_group_name = var.resource_group_name
  location            = var.location
  key_vault_key_id    = data.azurerm_key_vault_key.kek.id
  tags                = var.tags

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 Encryption Set.

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/diskEncryptionSets (Azure Resource Manager)

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

Example Usage from GitHub

ListDiskEncryptionSetsInAResourceGroup.json#L26
            "type": "Microsoft.Compute/diskEncryptionSets",
            "location": "westus",
            "tags": {
              "department": "Development",
              "project": "Encryption"
            },
ListDiskEncryptionSetsInASubscription.json#L25
            "type": "Microsoft.Compute/diskEncryptionSets",
            "location": "westus",
            "tags": {
              "department": "Development",
              "project": "Encryption"
            },
test-list-expected.json#L5
    "type": "Microsoft.Compute/diskEncryptionSets"
  }
test-list-expected.json#L5
    "type": "Microsoft.Compute/diskEncryptionSets"
  }
test-hydrate-expected.json#L13
    "type": "Microsoft.Compute/diskEncryptionSets"
  }
test-get-expected.json#L13
    "type": "Microsoft.Compute/diskEncryptionSets"
  }
ListDiskEncryptionSetsInASubscription.json#L25
            "type": "Microsoft.Compute/diskEncryptionSets",
            "location": "westus",
            "tags": {
              "department": "Development",
              "project": "Encryption"
            },
ListDiskEncryptionSetsInAResourceGroup.json#L26
            "type": "Microsoft.Compute/diskEncryptionSets",
            "location": "westus",
            "tags": {
              "department": "Development",
              "project": "Encryption"
            },
ListDiskEncryptionSetsInASubscription.json#L25
            "type": "Microsoft.Compute/diskEncryptionSets",
            "location": "westus",
            "tags": {
              "department": "Development",
              "project": "Encryption"
            },
ListDiskEncryptionSetsInAResourceGroup.json#L26
            "type": "Microsoft.Compute/diskEncryptionSets",
            "location": "westus",
            "tags": {
              "department": "Development",
              "project": "Encryption"
            },

Frequently asked questions

What is Azure Compute Disk Encryption Set?

Azure Compute Disk Encryption Set 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 Disk Encryption Set?

For Terraform, the mikamakusa/terraform, anmoltoppo/Terraform and VentsislavDinev/en_sample source code examples are useful. See the Terraform Example section for further details.

For Azure Resource Manager, the Azure/autorest.az, Azure/autorest.az and blinkops/blink-azure-query source code examples are useful. See the Azure Resource Manager Example section for further details.