Skip to content

Commit

Permalink
feat: Added UDTs for disks and ability to give a custom name to a dis…
Browse files Browse the repository at this point in the history
…k - `avm/res/compute/virtual-machine` (Azure#1517)

## Description

This pull request adds UDTs for OS disk and data disk. Also, included
the option to give a custom name to either disk.

## Pipeline Reference

| Pipeline |
| -------- |
|
[![avm.res.compute.virtual-machine](https://github.com/johnlokerse/bicep-registry-modules/actions/workflows/avm.res.compute.virtual-machine.yml/badge.svg?branch=johnlokerse%2Fissue1436)](https://github.com/johnlokerse/bicep-registry-modules/actions/workflows/avm.res.compute.virtual-machine.yml)
|

## Type of Change

<!-- Use the check-boxes [x] on the options that are relevant. -->

- [ ] Update to CI Environment or utlities (Non-module effecting
changes)
- [ ] Azure Verified Module updates:
- [ ] Bugfix containing backwards compatible bug fixes, and I have NOT
bumped the MAJOR or MINOR version in `version.json`:
- [ ] Someone has opened a bug report issue, and I have included "Closes
#{bug_report_issue_number}" in the PR description.
- [ ] The bug was found by the module author, and no one has opened an
issue to report it yet.
- [ ] Feature update backwards compatible feature updates, and I have
bumped the MINOR version in `version.json`.
- [ ] Breaking changes and I have bumped the MAJOR version in
`version.json`.
  - [ ] Update to documentation

## Checklist

- [ ] I'm sure there are no other open Pull Requests for the same
update/change
- [ ] I have run `Set-AVMModule` locally to generate the supporting
module files.
- [ ] My corresponding pipelines / checks run clean and green without
any errors or warnings

<!-- Please keep up to day with the contribution guide at
https://aka.ms/avm/contribute/bicep -->

---------

Co-authored-by: Rainer Halanek <[email protected]>
  • Loading branch information
johnlokerse and rahalan authored Apr 15, 2024
1 parent 2a212ba commit edf3d5d
Show file tree
Hide file tree
Showing 17 changed files with 686 additions and 157 deletions.
355 changes: 308 additions & 47 deletions avm/res/compute/virtual-machine/README.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions avm/res/compute/virtual-machine/extension/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.25.53.49325",
"templateHash": "5949079428725139834"
"version": "0.26.170.59819",
"templateHash": "8063436714999902780"
},
"name": "Virtual Machine Extensions",
"description": "This module deploys a Virtual Machine Extension.",
Expand Down
110 changes: 88 additions & 22 deletions avm/res/compute/virtual-machine/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ param imageReference object
param plan object = {}

@description('Required. Specifies the OS disk. For security reasons, it is recommended to specify DiskEncryptionSet into the osDisk object. Restrictions: DiskEncryptionSet cannot be enabled if Azure Disk Encryption (guest-VM encryption using bitlocker/DM-Crypt) is enabled on your VMs.')
param osDisk object
param osDisk osDiskType

@description('Optional. Specifies the data disks. For security reasons, it is recommended to specify DiskEncryptionSet into the dataDisk object. Restrictions: DiskEncryptionSet cannot be enabled if Azure Disk Encryption (guest-VM encryption using bitlocker/DM-Crypt) is enabled on your VMs.')
param dataDisks array = []
param dataDisks dataDisksType

@description('Optional. The flag that enables or disables a capability to have one or more managed data disks with UltraSSD_LRS storage account type on the VM or VMSS. Managed disks with storage account type UltraSSD_LRS can be added to a virtual machine or virtual machine scale set only if this property is enabled.')
param ultraSSDEnabled bool = false
Expand Down Expand Up @@ -474,35 +474,29 @@ resource vm 'Microsoft.Compute/virtualMachines@2022-11-01' = {
storageProfile: {
imageReference: imageReference
osDisk: {
name: '${name}-disk-os-01'
createOption: contains(osDisk, 'createOption') ? osDisk.createOption : 'FromImage'
deleteOption: contains(osDisk, 'deleteOption') ? osDisk.deleteOption : 'Delete'
name: osDisk.?name ?? '${name}-disk-os-01'
createOption: osDisk.?createOption ?? 'FromImage'
deleteOption: osDisk.?deleteOption ?? 'Delete'
diskSizeGB: osDisk.diskSizeGB
caching: contains(osDisk, 'caching') ? osDisk.caching : 'ReadOnly'
caching: osDisk.?caching ?? 'ReadOnly'
managedDisk: {
storageAccountType: osDisk.managedDisk.storageAccountType
diskEncryptionSet: contains(osDisk.managedDisk, 'diskEncryptionSet')
? {
id: osDisk.managedDisk.diskEncryptionSet.id
}
: null
diskEncryptionSet: {
id: osDisk.managedDisk.?diskEncryptionSetResourceId
}
}
}
dataDisks: [
for (dataDisk, index) in dataDisks: {
lun: index
name: '${name}-disk-data-${padLeft((index + 1), 2, '0')}'
for (dataDisk, index) in dataDisks ?? []: {
lun: dataDisk.?lun ?? index
name: dataDisk.?name ?? '${name}-disk-data-${padLeft((index + 1), 2, '0')}'
diskSizeGB: dataDisk.diskSizeGB
createOption: contains(dataDisk, 'createOption') ? dataDisk.createOption : 'Empty'
deleteOption: contains(dataDisk, 'deleteOption') ? dataDisk.deleteOption : 'Delete'
caching: contains(dataDisk, 'caching') ? dataDisk.caching : 'ReadOnly'
createOption: dataDisk.?createoption ?? 'Empty'
deleteOption: dataDisk.?deleteOption ?? 'Delete'
caching: dataDisk.?caching ?? 'ReadOnly'
managedDisk: {
storageAccountType: dataDisk.managedDisk.storageAccountType
diskEncryptionSet: contains(dataDisk.managedDisk, 'diskEncryptionSet')
? {
id: dataDisk.managedDisk.diskEncryptionSet.id
}
: null
diskEncryptionSet: dataDisk.?managedDisk.?diskEncryptionSet ?? null
}
}
]
Expand Down Expand Up @@ -552,6 +546,7 @@ resource vm 'Microsoft.Compute/virtualMachines@2022-11-01' = {
: null
priority: priority
evictionPolicy: enableEvictionPolicy ? 'Deallocate' : null
#disable-next-line BCP036
billingProfile: !empty(priority) && !empty(maxPriceForLowPriorityVm)
? {
maxPrice: json(maxPriceForLowPriorityVm)
Expand Down Expand Up @@ -1060,3 +1055,74 @@ type roleAssignmentType = {
@description('Optional. The Resource Id of the delegated managed identity resource.')
delegatedManagedIdentityResourceId: string?
}[]?

type osDiskType = {
@description('Optional. The disk name.')
name: string?

@description('Required. Specifies the size of an empty data disk in gigabytes.')
@maxValue(1023)
diskSizeGB: int

@description('Optional. Specifies how the virtual machine should be created.')
createOption: 'Attach' | 'Empty' | 'FromImage'?

@description('Optional. Specifies whether data disk should be deleted or detached upon VM deletion.')
deleteOption: 'Delete' | 'Detach'?

@description('Optional. Specifies the caching requirements.')
caching: 'None' | 'ReadOnly' | 'ReadWrite'?

@description('Required. The managed disk parameters.')
managedDisk: {
@description('Required. Specifies the storage account type for the managed disk.')
storageAccountType:
| 'PremiumV2_LRS'
| 'Premium_LRS'
| 'Premium_ZRS'
| 'StandardSSD_LRS'
| 'StandardSSD_ZRS'
| 'Standard_LRS'
| 'UltraSSD_LRS'

@description('Optional. Specifies the customer managed disk encryption set resource id for the managed disk.')
diskEncryptionSetResourceId: string?
}
}

type dataDisksType = {
@description('Optional. The disk name.')
name: string?

@description('Optional. Specifies the logical unit number of the data disk.')
lun: int?

@description('Required. Specifies the size of an empty data disk in gigabytes.')
@maxValue(1023)
diskSizeGB: int

@description('Optional. Specifies how the virtual machine should be created.')
createOption: 'Attach' | 'Empty' | 'FromImage'?

@description('Optional. Specifies whether data disk should be deleted or detached upon VM deletion.')
deleteOption: 'Delete' | 'Detach'?

@description('Optional. Specifies the caching requirements.')
caching: 'None' | 'ReadOnly' | 'ReadWrite'?

@description('Required. The managed disk parameters.')
managedDisk: {
@description('Required. Specifies the storage account type for the managed disk.')
storageAccountType:
| 'PremiumV2_LRS'
| 'Premium_LRS'
| 'Premium_ZRS'
| 'StandardSSD_LRS'
| 'StandardSSD_ZRS'
| 'Standard_LRS'
| 'UltraSSD_LRS'

@description('Optional. Specifies the customer managed disk encryption set resource id for the managed disk.')
diskEncryptionSetResourceId: string?
}
}[]?
Loading

0 comments on commit edf3d5d

Please sign in to comment.