Skip to content

Instantly share code, notes, and snippets.

@sireza
Created October 2, 2025 05:34
Show Gist options
  • Save sireza/7658bb7255f119a1e20656984e541e8a to your computer and use it in GitHub Desktop.
Save sireza/7658bb7255f119a1e20656984e541e8a to your computer and use it in GitHub Desktop.
Azure VM RedHat
@description('Name of the virtual machine')
param vmName string
@description('Size of the virtual machine')
param vmSize string = 'Standard_D2s_v3'
@description('Location for all resources')
param location string = resourceGroup().location
@description('Resource ID of the subnet where the VM will be deployed')
param subnetId string
@description('Username for the virtual machine administrator')
param adminUsername string
@description('Password for the virtual machine administrator')
@secure()
param adminPassword string
@description('Enable or disable boot diagnostics')
param bootDiagnosticsEnabled bool = true
@description('Storage account URI for boot diagnostics')
param bootDiagnosticsStorageUri string = ''
@description('The OS disk type')
@allowed([
'Standard_LRS'
'StandardSSD_LRS'
'Premium_LRS'
'StandardSSD_ZRS'
'Premium_ZRS'
])
param osDiskType string = 'StandardSSD_LRS'
@description('OS Disk size in GB')
@minValue(30)
param osDiskSizeGB int = 128
@description('The zone number of the VM')
@minValue(0)
@maxValue(3)
param zone int = 0
@description('Enable or disable system assigned managed identity')
param systemAssignedManagedIdentity bool = false
@description('List of user assigned managed identities')
param userAssignedIdentities object = {}
@description('Optional tags for resources')
param tags object = {}
@description('Version of Red Hat Enterprise Linux to use')
param rhVersion string = '9-gen2'
@description('Custom data to pass to the VM')
@secure()
param customData string = ''
// Network interface for the VM
resource nic 'Microsoft.Network/networkInterfaces@2023-05-01' = {
name: '${vmName}-nic'
location: location
tags: tags
properties: {
ipConfigurations: [
{
name: 'ipconfig1'
properties: {
subnet: {
id: subnetId
}
privateIPAllocationMethod: 'Dynamic'
}
}
]
enableIPForwarding: false
enableAcceleratedNetworking: true
}
}
// Red Hat VM deployment
resource vm 'Microsoft.Compute/virtualMachines@2023-07-01' = {
name: vmName
location: location
tags: tags
zones: zone != 0 ? [
string(zone)
] : null
identity: systemAssignedManagedIdentity || !empty(userAssignedIdentities) ? {
type: systemAssignedManagedIdentity && !empty(userAssignedIdentities) ? 'SystemAssigned, UserAssigned' : (systemAssignedManagedIdentity ? 'SystemAssigned' : 'UserAssigned')
userAssignedIdentities: !empty(userAssignedIdentities) ? userAssignedIdentities : null
} : null
properties: {
hardwareProfile: {
vmSize: vmSize
}
storageProfile: {
osDisk: {
createOption: 'FromImage'
managedDisk: {
storageAccountType: osDiskType
}
diskSizeGB: osDiskSizeGB
}
imageReference: {
publisher: 'RedHat'
offer: 'RHEL'
sku: rhVersion
version: 'latest'
}
}
networkProfile: {
networkInterfaces: [
{
id: nic.id
}
]
}
osProfile: {
computerName: vmName
adminUsername: adminUsername
adminPassword: adminPassword
customData: !empty(customData) ? base64(customData) : null
linuxConfiguration: {
disablePasswordAuthentication: false
provisionVMAgent: true
}
}
diagnosticsProfile: bootDiagnosticsEnabled ? {
bootDiagnostics: {
enabled: true
storageUri: !empty(bootDiagnosticsStorageUri) ? bootDiagnosticsStorageUri : null
}
} : null
}
}
// Output the VM ID
output vmId string = vm.id
// Output the VM private IP address
output vmPrivateIpAddress string = nic.properties.ipConfigurations[0].properties.privateIPAddress
// Output the VM principal ID (if system assigned managed identity is enabled)
output systemAssignedPrincipalId string = systemAssignedManagedIdentity ? vm.identity.principalId : ''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment