1. Using the Azure Native v2 provider, show me how to create a virtual machine with an external volume attached as a data disk.


    Sure, the program will first create a resource group, a virtual network and subnet, a network interface, a security group, and then the virtual machine itself. After creating these resources, it will create a managed disk and then attach it to the virtual machine.

    Here is the required Pulumi program in Go:

    package main import ( "github.com/pulumi/pulumi-azure-native/sdk/go/azure/compute" "github.com/pulumi/pulumi-azure-native/sdk/go/azure/network" "github.com/pulumi/pulumi-azure-native/sdk/go/azure/resources" "github.com/pulumi/pulumi/sdk/v3/go/pulumi" ) func main() { pulumi.Run(func(ctx *pulumi.Context) error { rg, err := resources.NewResourceGroup(ctx, "rg", nil) if err != nil { return err } vnet, err := network.NewVirtualNetwork(ctx, "vnet", &network.VirtualNetworkArgs{ ResourceGroupName: rg.Name, AddressSpace: &network.AddressSpaceArgs{ AddressPrefixes: pulumi.StringArray{ pulumi.String(""), }, }, }) if err != nil { return err } subnet, err := network.NewSubnet(ctx, "subnet", &network.SubnetArgs{ ResourceGroupName: rg.Name, VirtualNetworkName: vnet.Name, AddressPrefix: pulumi.String(""), }) if err != nil { return err } publicIp, err := network.NewPublicIPAddress(ctx, "publicIp", &network.PublicIPAddressArgs{ ResourceGroupName: rg.Name, }) if err != nil { return err } nic, err := network.NewNetworkInterface(ctx, "nic", &network.NetworkInterfaceArgs{ ResourceGroupName: rg.Name, IpConfigurations: network.NetworkInterfaceIPConfigurationArray{ &network.NetworkInterfaceIPConfigurationArgs{ Name: pulumi.String("webserveripcfg"), Subnet: &network.SubnetArgs{ Id: subnet.ID(), }, PrivateIPAllocationMethod: pulumi.String("Dynamic"), PublicIPAddress: &network.PublicIPAddressArgs{ Id: publicIp.ID(), }, }, }, }) if err != nil { return err } vm, err := compute.NewVirtualMachine(ctx, "vm", &compute.VirtualMachineArgs{ ResourceGroupName: rg.Name, NetworkProfile: &compute.NetworkProfileArgs{ NetworkInterfaces: compute.NetworkInterfaceArray{ &compute.NetworkInterfaceArgs{ Id: nic.ID(), Properties: &compute.NetworkInterfacePropertiesArgs{ Primary: pulumi.Bool(true), }, }, }, }, HardwareProfile: &compute.HardwareProfileArgs{ VmSize: pulumi.String("Standard_A0"), }, StorageProfile: &compute.StorageProfileArgs{ ImageReference: &compute.ImageReferenceArgs{ Publisher: pulumi.String("MicrosoftWindowsServer"), Offer: pulumi.String("WindowsServer"), Sku: pulumi.String("2012-R2-Datacenter"), Version: pulumi.String("latest"), }, OsDisk: &compute.OSDiskArgs{ CreateOption: pulumi.String("FromImage"), Name: pulumi.String("myosdisk1"), }, }, OsProfile: &compute.OSProfileArgs{ ComputerName: pulumi.String("hostname"), AdminUsername: pulumi.String("testadmin"), AdminPassword: pulumi.String("Password1234!"), WindowsConfiguration: &compute.WindowsConfigurationArgs{ EnableAutomaticUpdates: pulumi.Bool(true), }, }, }) if err != nil { return err } disk, err := compute.NewDisk(ctx, "dataDisk", &compute.DiskArgs{ ResourceGroupName: rg.Name, CreationData: &compute.CreationDataArgs{ CreateOption: pulumi.String("Empty"), }, DiskSizeGB: pulumi.Int(100), }) if err != nil { return err } _, err = compute.NewVirtualMachineDataDiskAttachment(ctx, "vm_dataDisk", &compute.VirtualMachineDataDiskAttachmentArgs{ ManagedDisk: &compute.ManagedDiskParametersArgs{ Id: disk.ID(), }, Lun: pulumi.Int(0), VirtualMachineId: vm.ID(), CreateOption: pulumi.String("Attach"), ResourceGroupName: rg.Name, VirtualMachineName: vm.Name, }) if err != nil { return err } ctx.Export("publicIP", publicIp.IpAddress) return nil }) }

    Just make sure you replace the placeholders with your actual values. This code will create a new virtual machine with its own network and a managed disk named "dataDisk" which will be attached to the VM as data disk after the VM is created. The VM is using the latest "Windows Server 2012 R2 Datacenter" image from Microsoft.

    Relevant Pulumi registry documentation: