Manages a managed disk.
resource "azurerm_resource_group" "example" {
name = "example-resources"
location = "West Europe"
}
resource "azurerm_managed_disk" "example" {
name = "acctestmd"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
storage_account_type = "Standard_LRS"
create_option = "Empty"
disk_size_gb = "1"
tags = {
environment = "staging"
}
}
resource "azurerm_resource_group" "example" {
name = "example-resources"
location = "West Europe"
}
resource "azurerm_managed_disk" "source" {
name = "acctestmd1"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
storage_account_type = "Standard_LRS"
create_option = "Empty"
disk_size_gb = "1"
tags = {
environment = "staging"
}
}
resource "azurerm_managed_disk" "copy" {
name = "acctestmd2"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
storage_account_type = "Standard_LRS"
create_option = "Copy"
source_resource_id = azurerm_managed_disk.source.id
disk_size_gb = "1"
tags = {
environment = "staging"
}
}
The following arguments are supported:
name
- (Required) Specifies the name of the Managed Disk. Changing this forces a new resource to be created.
resource_group_name
- (Required) The name of the Resource Group where the Managed Disk should exist. Changing this forces a new resource to be created.
location
- (Required) Specified the supported Azure location where the resource exists. Changing this forces a new resource to be created.
storage_account_type
- (Required) The type of storage to use for the managed disk. Possible values are Standard_LRS
, StandardSSD_ZRS
, Premium_LRS
, PremiumV2_LRS
, Premium_ZRS
, StandardSSD_LRS
or UltraSSD_LRS
.
create_option
- (Required) The method to use when creating the managed disk. Changing this forces a new resource to be created. Possible values include: * Import
- Import a VHD file in to the managed disk (VHD specified with source_uri
). * ImportSecure
- Securely import a VHD file in to the managed disk (VHD specified with source_uri
). * Empty
- Create an empty managed disk. * Copy
- Copy an existing managed disk or snapshot (specified with source_resource_id
). * FromImage
- Copy a Platform Image (specified with image_reference_id
) * Restore
- Set by Azure Backup or Site Recovery on a restored disk (specified with source_resource_id
). * Upload
- Upload a VHD disk with the help of SAS URL (to be used with upload_size_bytes
).disk_encryption_set_id
- (Optional) The ID of a Disk Encryption Set which should be used to encrypt this Managed Disk. Conflicts with secure_vm_disk_encryption_set_id
.disk_iops_read_write
- (Optional) The number of IOPS allowed for this disk; only settable for UltraSSD disks and PremiumV2 disks. One operation can transfer between 4k and 256k bytes.
disk_mbps_read_write
- (Optional) The bandwidth allowed for this disk; only settable for UltraSSD disks and PremiumV2 disks. MBps means millions of bytes per second.
disk_iops_read_only
- (Optional) The number of IOPS allowed across all VMs mounting the shared disk as read-only; only settable for UltraSSD disks and PremiumV2 disks with shared disk enabled. One operation can transfer between 4k and 256k bytes.
disk_mbps_read_only
- (Optional) The bandwidth allowed across all VMs mounting the shared disk as read-only; only settable for UltraSSD disks and PremiumV2 disks with shared disk enabled. MBps means millions of bytes per second.
upload_size_bytes
- (Optional) Specifies the size of the managed disk to create in bytes. Required when create_option
is Upload
. The value must be equal to the source disk to be copied in bytes. Source disk size could be calculated with ls -l
or wc -c
. More information can be found at Copy a managed disk. Changing this forces a new resource to be created.
disk_size_gb
- (Optional) (Optional, Required for a new managed disk) Specifies the size of the managed disk to create in gigabytes. If create_option
is Copy
or FromImage
, then the value must be equal to or greater than the source's size. The size can only be increased.
edge_zone
- (Optional) Specifies the Edge Zone within the Azure Region where this Managed Disk should exist. Changing this forces a new Managed Disk to be created.
encryption_settings
- (Optional) A encryption_settings
block as defined below.
hyper_v_generation
- (Optional) The HyperV Generation of the Disk when the source of an Import
or Copy
operation targets a source that contains an operating system. Possible values are V1
and V2
. For ImportSecure
it must be set to V2
. Changing this forces a new resource to be created.
image_reference_id
- (Optional) ID of an existing platform/marketplace disk image to copy when create_option
is FromImage
. This field cannot be specified if gallery_image_reference_id is specified. Changing this forces a new resource to be created.
gallery_image_reference_id
- (Optional) ID of a Gallery Image Version to copy when create_option
is FromImage
. This field cannot be specified if image_reference_id is specified. Changing this forces a new resource to be created.
logical_sector_size
- (Optional) Logical Sector Size. Possible values are: 512
and 4096
. Defaults to 4096
. Changing this forces a new resource to be created.
optimized_frequent_attach_enabled
- (Optional) Specifies whether this Managed Disk should be optimized for frequent disk attachments (where a disk is attached/detached more than 5 times in a day). Defaults to false
.performance_plus_enabled
- (Optional) Specifies whether Performance Plus is enabled for this Managed Disk. Defaults to false
. Changing this forces a new resource to be created.os_type
- (Optional) Specify a value when the source of an Import
, ImportSecure
or Copy
operation targets a source that contains an operating system. Valid values are Linux
or Windows
.
source_resource_id
- (Optional) The ID of an existing Managed Disk or Snapshot to copy when create_option
is Copy
or the recovery point to restore when create_option
is Restore
. Changing this forces a new resource to be created.
source_uri
- (Optional) URI to a valid VHD file to be used when create_option
is Import
or ImportSecure
. Changing this forces a new resource to be created.
storage_account_id
- (Optional) The ID of the Storage Account where the source_uri
is located. Required when create_option
is set to Import
or ImportSecure
. Changing this forces a new resource to be created.
tier
- (Optional) The disk performance tier to use. Possible values are documented here. This feature is currently supported only for premium SSDs.
max_shares
- (Optional) The maximum number of VMs that can attach to the disk at the same time. Value greater than one indicates a disk that can be mounted on multiple VMs at the same time.trusted_launch_enabled
- (Optional) Specifies if Trusted Launch is enabled for the Managed Disk. Changing this forces a new resource to be created.security_type
- (Optional) Security Type of the Managed Disk when it is used for a Confidential VM. Possible values are ConfidentialVM_VMGuestStateOnlyEncryptedWithPlatformKey
, ConfidentialVM_DiskEncryptedWithPlatformKey
and ConfidentialVM_DiskEncryptedWithCustomerKey
. Changing this forces a new resource to be created.secure_vm_disk_encryption_set_id
- (Optional) The ID of the Disk Encryption Set which should be used to Encrypt this OS Disk when the Virtual Machine is a Confidential VM. Conflicts with disk_encryption_set_id
. Changing this forces a new resource to be created.on_demand_bursting_enabled
- (Optional) Specifies if On-Demand Bursting is enabled for the Managed Disk.tags
- (Optional) A mapping of tags to assign to the resource.
zone
- (Optional) Specifies the Availability Zone in which this Managed Disk should be located. Changing this property forces a new resource to be created.
network_access_policy
- (Optional) Policy for accessing the disk via network. Allowed values are AllowAll
, AllowPrivate
, and DenyAll
.
disk_access_id
- (Optional) The ID of the disk access resource for using private endpoints on disks.
public_network_access_enabled
- (Optional) Whether it is allowed to access the disk via public network. Defaults to true
.For more information on managed disks, such as sizing options and pricing, please check out the Azure Documentation.
The disk_encryption_key
block supports:
secret_url
- (Required) The URL to the Key Vault Secret used as the Disk Encryption Key. This can be found as id
on the azurerm_key_vault_secret
resource.
source_vault_id
- (Required) The ID of the source Key Vault. This can be found as id
on the azurerm_key_vault
resource.
The encryption_settings
block supports:
disk_encryption_key
- (Optional) A disk_encryption_key
block as defined above.
key_encryption_key
- (Optional) A key_encryption_key
block as defined below.
The key_encryption_key
block supports:
key_url
- (Required) The URL to the Key Vault Key used as the Key Encryption Key. This can be found as id
on the azurerm_key_vault_key
resource.
source_vault_id
- (Required) The ID of the source Key Vault. This can be found as id
on the azurerm_key_vault
resource.
In addition to the Arguments listed above - the following Attributes are exported:
id
- The ID of the Managed Disk.The timeouts
block allows you to specify timeouts for certain actions:
create
- (Defaults to 30 minutes) Used when creating the Managed Disk.update
- (Defaults to 30 minutes) Used when updating the Managed Disk.read
- (Defaults to 5 minutes) Used when retrieving the Managed Disk.delete
- (Defaults to 30 minutes) Used when deleting the Managed Disk.Managed Disks can be imported using the resource id
, e.g.
terraform import azurerm_managed_disk.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/Microsoft.Compute/disks/manageddisk1