Azure Compute Managed Disk
This page shows how to write Terraform for Compute Managed Disk and write them securely.
azurerm_managed_disk (Terraform)
The Managed Disk in Compute can be configured in Terraform with the resource name azurerm_managed_disk
. The following sections describe 10 examples of how to use the resource and its parameters.
Example Usage from GitHub
resource "azurerm_managed_disk" "disk0" {
name = "disk0"
location = var.region
resource_group_name = var.rg
storage_account_type = var.disk_type
create_option = "Empty"
resource "azurerm_managed_disk" "example" {
name = var.firstDiskAttribute[0]
location = var.region
resource_group_name = azurerm_resource_group.example.name
storage_account_type = "Standard_LRS"
create_option = "Empty"
resource "azurerm_managed_disk" "managed_disk" {
name = "manageddisk01"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
storage_account_type = "Standard_LRS"
create_option = "Empty"
resource "azurerm_managed_disk" "disk-01-vm-07-server-04" {
name = "disk-01-vm-07-server-04"
location = azurerm_resource_group.rg-br-server-prd.location
resource_group_name = azurerm_resource_group.rg-br-server-prd.name
storage_account_type = "Standard_LRS"
create_option = "Empty"
resource "azurerm_managed_disk" "disk0" {
name = "disk0"
location = var.region
resource_group_name = var.rg
storage_account_type = var.disk_type
create_option = "Empty"
resource "azurerm_managed_disk" "managedisk_vhgrrpoddb01" {
count = length(var.extradisks_vhgrrpoddb01)
name = element(var.extradisks_vhgrrpoddb01,count.index)
location = var.location
resource_group_name = azurerm_resource_group.rg.name
storage_account_type = element(var.extradisks_storage_account_type1,count.index)
resource "azurerm_managed_disk" "standard" {
name = "standard"
resource_group_name = "fake_resource_group"
location = "eastus"
create_option = "Empty"
resource "azurerm_managed_disk" "positive1" {
name = "acctestmd"
location = "West US 2"
resource_group_name = azurerm_resource_group.example.name
storage_account_type = "Standard_LRS"
create_option = "Empty"
resource "azurerm_managed_disk" "source" {
name = "acctestmd1"
location = "West US 2"
resource_group_name = azurerm_resource_group.example.name
storage_account_type = "Standard_LRS"
create_option = "Empty"
resource "azurerm_managed_disk" "postfacto_v1_redis" {
name = "k8s_postfacto_v1_redis_disk"
location = azurerm_resource_group.rg.location
# If storage is ZRS, to make ZRS available at multiple zones, leave the array empty
# Note: ZRS uses CSI drive, which should be installed if k8s < 1.21.0
zones = [1]
Security Best Practices for azurerm_managed_disk
There is 1 setting in azurerm_managed_disk that should be taken care of for security reasons. The following section explain an overview and example code.
Ensure to enable the encryption on managed disks
It is better to enable the encryption on managed disks.
Parameters
-
create_option
required - string -
disk_encryption_set_id
optional - string -
disk_iops_read_write
optional computed - number -
disk_mbps_read_write
optional computed - number -
disk_size_gb
optional computed - number -
id
optional computed - string -
image_reference_id
optional - string -
location
required - string -
name
required - string -
os_type
optional - string -
resource_group_name
required - string -
source_resource_id
optional - string -
source_uri
optional computed - string -
storage_account_id
optional - string -
storage_account_type
required - string -
tags
optional - map from string to string -
zones
optional - list of 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 managed disk.
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_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.
Azure Resource Manager Example
Azure Resource Manager code does not have the related resource.
Frequently asked questions
What is Azure Compute Managed Disk?
Azure Compute Managed Disk 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 Managed Disk?
For Terraform, the lasertown/throughput_test, ani50/tfstructuraldatatype and shankar5885/sampletf source code examples are useful. See the Terraform Example section for further details.