Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: deploy vm's with ZRS data disk(s) #3864

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
197 changes: 197 additions & 0 deletions avm/res/compute/virtual-machine/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ The following section provides usage examples for the module, which were used to
- [Deploying Windows VM with premium SSDv2 data disk](#example-10-deploying-windows-vm-with-premium-ssdv2-data-disk)
- [Using disk encryption set for the VM.](#example-11-using-disk-encryption-set-for-the-vm)
- [Adding the VM to a VMSS.](#example-12-adding-the-vm-to-a-vmss)
- [Deploying Windows VM in a defined zone with a premium zrs data disk](#example-13-deploying-windows-vm-in-a-defined-zone-with-a-premium-zrs-data-disk)

### Example 1: _Using automanage for the VM._

Expand Down Expand Up @@ -4736,6 +4737,202 @@ param virtualMachineScaleSetResourceId = '<virtualMachineScaleSetResourceId>'
</details>
<p>

### Example 13: _Deploying Windows VM in a defined zone with a premium zrs data disk_

This instance deploys the module with a premium zrs data disk.


<details>

<summary>via Bicep module</summary>

```bicep
module virtualMachine 'br/public:avm/res/compute/virtual-machine:<version>' = {
name: 'virtualMachineDeployment'
params: {
// Required parameters
adminUsername: 'localAdminUser'
imageReference: {
offer: 'WindowsServer'
publisher: 'MicrosoftWindowsServer'
sku: '2022-datacenter-azure-edition'
version: 'latest'
}
name: 'cvmwinssdv2'
nicConfigurations: [
{
ipConfigurations: [
{
name: 'ipconfig01'
subnetResourceId: '<subnetResourceId>'
}
]
nicSuffix: '-nic-01'
}
]
osDisk: {
caching: 'ReadWrite'
diskSizeGB: 128
managedDisk: {
storageAccountType: 'Premium_ZRS'
}
}
osType: 'Windows'
vmSize: 'Standard_D2s_v3'
zone: 2
// Non-required parameters
adminPassword: '<adminPassword>'
dataDisks: [
{
caching: 'None'
diskSizeGB: 1024
managedDisk: {
storageAccountType: 'Premium_ZRS'
}
}
]
location: '<location>'
}
}
```

</details>
<p>

<details>

<summary>via JSON parameters file</summary>

```json
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
// Required parameters
"adminUsername": {
"value": "localAdminUser"
},
"imageReference": {
"value": {
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2022-datacenter-azure-edition",
"version": "latest"
}
},
"name": {
"value": "cvmwinssdv2"
},
"nicConfigurations": {
"value": [
{
"ipConfigurations": [
{
"name": "ipconfig01",
"subnetResourceId": "<subnetResourceId>"
}
],
"nicSuffix": "-nic-01"
}
]
},
"osDisk": {
"value": {
"caching": "ReadWrite",
"diskSizeGB": 128,
"managedDisk": {
"storageAccountType": "Premium_ZRS"
}
}
},
"osType": {
"value": "Windows"
},
"vmSize": {
"value": "Standard_D2s_v3"
},
"zone": {
"value": 2
},
// Non-required parameters
"adminPassword": {
"value": "<adminPassword>"
},
"dataDisks": {
"value": [
{
"caching": "None",
"diskSizeGB": 1024,
"managedDisk": {
"storageAccountType": "Premium_ZRS"
}
}
]
},
"location": {
"value": "<location>"
}
}
}
```

</details>
<p>

<details>

<summary>via Bicep parameters file</summary>

```bicep-params
using 'br/public:avm/res/compute/virtual-machine:<version>'

// Required parameters
param adminUsername = 'localAdminUser'
param imageReference = {
offer: 'WindowsServer'
publisher: 'MicrosoftWindowsServer'
sku: '2022-datacenter-azure-edition'
version: 'latest'
}
param name = 'cvmwinssdv2'
param nicConfigurations = [
{
ipConfigurations: [
{
name: 'ipconfig01'
subnetResourceId: '<subnetResourceId>'
}
]
nicSuffix: '-nic-01'
}
]
param osDisk = {
caching: 'ReadWrite'
diskSizeGB: 128
managedDisk: {
storageAccountType: 'Premium_ZRS'
}
}
param osType = 'Windows'
param vmSize = 'Standard_D2s_v3'
param zone = 2
// Non-required parameters
param adminPassword = '<adminPassword>'
param dataDisks = [
{
caching: 'None'
diskSizeGB: 1024
managedDisk: {
storageAccountType: 'Premium_ZRS'
}
}
]
param location = '<location>'
```

</details>
<p>

## Parameters

**Required parameters**
Expand Down
2 changes: 1 addition & 1 deletion avm/res/compute/virtual-machine/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ resource managedDataDisks 'Microsoft.Compute/disks@2024-03-02' = [
diskIOPSReadWrite: dataDisk.?diskIOPSReadWrite
diskMBpsReadWrite: dataDisk.?diskMBpsReadWrite
}
zones: zone != 0 ? array(string(zone)) : null
zones: zone != 0 && !contains(dataDisk.managedDisk.storageAccountType, 'ZRS') ? array(string(zone)) : null
}
]

Expand Down
4 changes: 2 additions & 2 deletions avm/res/compute/virtual-machine/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"_generator": {
"name": "bicep",
"version": "0.31.92.45157",
"templateHash": "8928644602939334563"
"templateHash": "7351283414350296453"
},
"name": "Virtual Machines",
"description": "This module deploys a Virtual Machine with one or multiple NICs and optionally one or multiple public IPs.",
Expand Down Expand Up @@ -1021,7 +1021,7 @@
"diskIOPSReadWrite": "[tryGet(coalesce(parameters('dataDisks'), createArray())[copyIndex()], 'diskIOPSReadWrite')]",
"diskMBpsReadWrite": "[tryGet(coalesce(parameters('dataDisks'), createArray())[copyIndex()], 'diskMBpsReadWrite')]"
},
"zones": "[if(not(equals(parameters('zone'), 0)), array(string(parameters('zone'))), null())]"
"zones": "[if(and(not(equals(parameters('zone'), 0)), not(contains(coalesce(parameters('dataDisks'), createArray())[copyIndex()].managedDisk.storageAccountType, 'ZRS'))), array(string(parameters('zone'))), null())]"
},
"vm": {
"type": "Microsoft.Compute/virtualMachines",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
@description('Required. The name of the Virtual Network to create.')
param virtualNetworkName string

@description('Optional. The location to deploy to.')
param location string = resourceGroup().location

var addressPrefix = '10.0.0.0/16'

resource virtualNetwork 'Microsoft.Network/virtualNetworks@2023-04-01' = {
name: virtualNetworkName
location: location
properties: {
addressSpace: {
addressPrefixes: [
addressPrefix
]
}
subnets: [
{
name: 'defaultSubnet'
properties: {
addressPrefix: cidrSubnet(addressPrefix, 16, 0)
}
}
]
}
}

@description('The resource ID of the created Virtual Network Subnet.')
output subnetResourceId string = virtualNetwork.properties.subnets[0].id
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
targetScope = 'subscription'

metadata name = 'Deploying Windows VM in a defined zone with a premium zrs data disk'
metadata description = 'This instance deploys the module with a premium zrs data disk.'

// ========== //
// Parameters //
// ========== //

@description('Optional. The name of the resource group to deploy for testing purposes.')
@maxLength(90)
param resourceGroupName string = 'dep-${namePrefix}-compute.virtualMachines-${serviceShort}-rg'

// Capacity constraints for VM type
#disable-next-line no-hardcoded-location
var enforcedLocation = 'uksouth'

@description('Optional. A short identifier for the kind of deployment. Should be kept short to not run into resource-name length-constraints.')
param serviceShort string = 'cvmwinssdv2'

@description('Optional. The password to leverage for the login.')
@secure()
param password string = newGuid()

@description('Optional. A token to inject into the name of each resource.')
param namePrefix string = '#_namePrefix_#'

// ============ //
// Dependencies //
// ============ //

// General resources
// =================
resource resourceGroup 'Microsoft.Resources/resourceGroups@2021-04-01' = {
name: resourceGroupName
location: enforcedLocation
}

module nestedDependencies 'dependencies.bicep' = {
scope: resourceGroup
name: '${uniqueString(deployment().name, enforcedLocation)}-nestedDependencies'
params: {
location: enforcedLocation
virtualNetworkName: 'dep-${namePrefix}-vnet-${serviceShort}'
}
}

// ============== //
// Test Execution //
// ============== //
@batchSize(1)
module testDeployment '../../../main.bicep' = [
for iteration in ['init', 'idem']: {
scope: resourceGroup
name: '${uniqueString(deployment().name, enforcedLocation)}-test-${serviceShort}-${iteration}'
params: {
location: enforcedLocation
name: '${namePrefix}${serviceShort}'
adminUsername: 'localAdminUser'
imageReference: {
publisher: 'MicrosoftWindowsServer'
offer: 'WindowsServer'
sku: '2022-datacenter-azure-edition'
version: 'latest'
}
zone: 2
nicConfigurations: [
{
ipConfigurations: [
{
name: 'ipconfig01'
subnetResourceId: nestedDependencies.outputs.subnetResourceId
}
]
nicSuffix: '-nic-01'
}
]
osDisk: {
diskSizeGB: 128
caching: 'ReadWrite'
managedDisk: {
storageAccountType: 'Premium_ZRS'
}
}
dataDisks: [
{
diskSizeGB: 1024
caching: 'None'
managedDisk: {
storageAccountType: 'Premium_ZRS'
}
}
]
osType: 'Windows'
vmSize: 'Standard_D2s_v3'
adminPassword: password
}
}
]