DataDiskAttachment

class DataDiskAttachment : KotlinCustomResource

Manages attaching a Disk to a Virtual Machine.

NOTE: Data Disks can be attached either directly on the azure.compute.VirtualMachine resource, or using the azure.compute.DataDiskAttachment resource - but the two cannot be used together. If both are used against the same Virtual Machine, spurious changes will occur. Please Note: only Managed Disks are supported via this separate resource, Unmanaged Disks can be attached using the storage_data_disk block in the azure.compute.VirtualMachine resource.

Example Usage

package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.azure.core.ResourceGroup;
import com.pulumi.azure.core.ResourceGroupArgs;
import com.pulumi.azure.network.VirtualNetwork;
import com.pulumi.azure.network.VirtualNetworkArgs;
import com.pulumi.azure.network.Subnet;
import com.pulumi.azure.network.SubnetArgs;
import com.pulumi.azure.network.NetworkInterface;
import com.pulumi.azure.network.NetworkInterfaceArgs;
import com.pulumi.azure.network.inputs.NetworkInterfaceIpConfigurationArgs;
import com.pulumi.azure.compute.VirtualMachine;
import com.pulumi.azure.compute.VirtualMachineArgs;
import com.pulumi.azure.compute.inputs.VirtualMachineStorageImageReferenceArgs;
import com.pulumi.azure.compute.inputs.VirtualMachineStorageOsDiskArgs;
import com.pulumi.azure.compute.inputs.VirtualMachineOsProfileArgs;
import com.pulumi.azure.compute.inputs.VirtualMachineOsProfileLinuxConfigArgs;
import com.pulumi.azure.compute.ManagedDisk;
import com.pulumi.azure.compute.ManagedDiskArgs;
import com.pulumi.azure.compute.DataDiskAttachment;
import com.pulumi.azure.compute.DataDiskAttachmentArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
final var config = ctx.config();
final var prefix = config.get("prefix").orElse("example");
final var vmName = String.format("%s-vm", prefix);
var exampleResourceGroup = new ResourceGroup("exampleResourceGroup", ResourceGroupArgs.builder()
.location("West Europe")
.build());
var mainVirtualNetwork = new VirtualNetwork("mainVirtualNetwork", VirtualNetworkArgs.builder()
.addressSpaces("10.0.0.0/16")
.location(exampleResourceGroup.location())
.resourceGroupName(exampleResourceGroup.name())
.build());
var internal = new Subnet("internal", SubnetArgs.builder()
.resourceGroupName(exampleResourceGroup.name())
.virtualNetworkName(mainVirtualNetwork.name())
.addressPrefixes("10.0.2.0/24")
.build());
var mainNetworkInterface = new NetworkInterface("mainNetworkInterface", NetworkInterfaceArgs.builder()
.location(exampleResourceGroup.location())
.resourceGroupName(exampleResourceGroup.name())
.ipConfigurations(NetworkInterfaceIpConfigurationArgs.builder()
.name("internal")
.subnetId(internal.id())
.privateIpAddressAllocation("Dynamic")
.build())
.build());
var exampleVirtualMachine = new VirtualMachine("exampleVirtualMachine", VirtualMachineArgs.builder()
.location(exampleResourceGroup.location())
.resourceGroupName(exampleResourceGroup.name())
.networkInterfaceIds(mainNetworkInterface.id())
.vmSize("Standard_F2")
.storageImageReference(VirtualMachineStorageImageReferenceArgs.builder()
.publisher("Canonical")
.offer("0001-com-ubuntu-server-focal")
.sku("20_04-lts")
.version("latest")
.build())
.storageOsDisk(VirtualMachineStorageOsDiskArgs.builder()
.name("myosdisk1")
.caching("ReadWrite")
.createOption("FromImage")
.managedDiskType("Standard_LRS")
.build())
.osProfile(VirtualMachineOsProfileArgs.builder()
.computerName(vmName)
.adminUsername("testadmin")
.adminPassword("Password1234!")
.build())
.osProfileLinuxConfig(VirtualMachineOsProfileLinuxConfigArgs.builder()
.disablePasswordAuthentication(false)
.build())
.build());
var exampleManagedDisk = new ManagedDisk("exampleManagedDisk", ManagedDiskArgs.builder()
.location(exampleResourceGroup.location())
.resourceGroupName(exampleResourceGroup.name())
.storageAccountType("Standard_LRS")
.createOption("Empty")
.diskSizeGb(10)
.build());
var exampleDataDiskAttachment = new DataDiskAttachment("exampleDataDiskAttachment", DataDiskAttachmentArgs.builder()
.managedDiskId(exampleManagedDisk.id())
.virtualMachineId(exampleVirtualMachine.id())
.lun("10")
.caching("ReadWrite")
.build());
}
}

Import

Virtual Machines Data Disk Attachments can be imported using the resource id, e.g.

$ pulumi import azure:compute/dataDiskAttachment:DataDiskAttachment example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/Microsoft.Compute/virtualMachines/machine1/dataDisks/disk1

Properties

Link copied to clipboard
val caching: Output<String>

Specifies the caching requirements for this Data Disk. Possible values include None, ReadOnly and ReadWrite.

Link copied to clipboard
val createOption: Output<String>?

The Create Option of the Data Disk, such as Empty or Attach. Defaults to Attach. Changing this forces a new resource to be created.

Link copied to clipboard
val id: Output<String>
Link copied to clipboard
val lun: Output<Int>

The Logical Unit Number of the Data Disk, which needs to be unique within the Virtual Machine. Changing this forces a new resource to be created.

Link copied to clipboard
val managedDiskId: Output<String>

The ID of an existing Managed Disk which should be attached. Changing this forces a new resource to be created.

Link copied to clipboard
val pulumiChildResources: Set<KotlinResource>
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
val urn: Output<String>
Link copied to clipboard

The ID of the Virtual Machine to which the Data Disk should be attached. Changing this forces a new resource to be created.

Link copied to clipboard

Specifies if Write Accelerator is enabled on the disk. This can only be enabled on Premium_LRS managed disks with no caching and M-Series VMs. Defaults to false.