Last active
March 15, 2025 01:00
-
-
Save snandam/89ddfcbe0fc7924d1ddf640ff0cf7fcf to your computer and use it in GitHub Desktop.
azure-vm-template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#", | |
"handler": "Microsoft.Azure.CreateUIDef", | |
"version": "0.1.2-preview", | |
"parameters": { | |
"basics": [ | |
{ | |
"name": "vmName", | |
"type": "Microsoft.Common.TextBox", | |
"label": "Virtual Machine Name", | |
"defaultValue": "MyVM", | |
"toolTip": "Name of the Virtual Machine", | |
"constraints": { | |
"required": true, | |
"regex": "^[a-z0-9A-Z]{3,24}$", | |
"validationMessage": "VM name must be between 3 and 24 characters, containing only letters and numbers." | |
} | |
}, | |
{ | |
"name": "adminUsername", | |
"type": "Microsoft.Common.TextBox", | |
"label": "Admin Username", | |
"defaultValue": "azureadmin", | |
"toolTip": "Admin username for the Virtual Machine", | |
"constraints": { | |
"required": true, | |
"regex": "^[a-z0-9A-Z]{1,30}$", | |
"validationMessage": "Username must use alphanumeric characters only." | |
} | |
}, | |
{ | |
"name": "adminPassword", | |
"type": "Microsoft.Common.PasswordBox", | |
"label": { | |
"password": "Admin Password", | |
"confirmPassword": "Confirm Password" | |
}, | |
"toolTip": "Admin password for the Virtual Machine", | |
"constraints": { | |
"required": true, | |
"regex": "^(?=.*[A-Z])(?=.*[.!@#$%^&*()-_=+])(?=.*[0-9])(?=.*[a-z]).{12,}$", | |
"validationMessage": "Password must be at least 12 characters and contain uppercase letters, lowercase letters, numbers, and special characters." | |
}, | |
"options": { | |
"hideConfirmation": false | |
} | |
} | |
], | |
"steps": [ | |
{ | |
"name": "vmSettings", | |
"label": "VM Settings", | |
"elements": [ | |
{ | |
"name": "vmSize", | |
"type": "Microsoft.Compute.SizeSelector", | |
"label": "Virtual Machine Size", | |
"toolTip": "The size of the Virtual Machine", | |
"defaultValue": "Standard_DS1_v2", | |
"recommendedSizes": [ | |
"Standard_B2s", | |
"Standard_DS1_v2", | |
"Standard_DS2_v2", | |
"Standard_DS3_v2" | |
], | |
"constraints": { | |
"allowedSizes": [ | |
"Standard_B2s", | |
"Standard_DS1_v2", | |
"Standard_DS2_v2", | |
"Standard_DS3_v2", | |
"Standard_DS4_v2", | |
"Standard_DS5_v2", | |
"Standard_D2s_v3", | |
"Standard_D4s_v3", | |
"Standard_D8s_v3" | |
] | |
}, | |
"osPlatform": "Linux", | |
"count": 1 | |
}, | |
{ | |
"name": "networkSettings", | |
"type": "Microsoft.Common.Section", | |
"label": "Network Settings", | |
"elements": [ | |
{ | |
"name": "vnetSelector", | |
"type": "Microsoft.Network.VirtualNetworkCombo", | |
"label": { | |
"virtualNetwork": "Virtual network", | |
"subnets": "Subnets" | |
}, | |
"toolTip": { | |
"virtualNetwork": "Select an existing virtual network", | |
"subnets": "Select an existing subnet" | |
}, | |
"defaultValue": { | |
"VirtualNetworkName": "" | |
}, | |
"constraints": { | |
"minAddressPrefixSize": "/29" | |
}, | |
"options": { | |
"hideExisting": false | |
}, | |
"subnets": { | |
"subnet1": { | |
"label": "Subnet", | |
"constraints": { | |
"minAddressCount": 4, | |
"minAddressPrefixSize": "/29" | |
} | |
} | |
}, | |
"visible": true | |
} | |
] | |
}, | |
{ | |
"name": "osSettings", | |
"type": "Microsoft.Common.Section", | |
"label": "Operating System Settings", | |
"elements": [ | |
{ | |
"name": "OSVersion", | |
"type": "Microsoft.Common.DropDown", | |
"label": "OS Version", | |
"defaultValue": "8-lvm-gen2", | |
"toolTip": "The OS version for the VM", | |
"constraints": { | |
"allowedValues": [ | |
{ | |
"label": "Red Hat Enterprise Linux 8", | |
"value": "8-lvm-gen2" | |
} | |
], | |
"required": true | |
} | |
} | |
] | |
} | |
] | |
}, | |
{ | |
"name": "ockamSettings", | |
"label": "Ockam Configuration", | |
"elements": [ | |
{ | |
"name": "nodeTicket", | |
"type": "Microsoft.Common.TextBox", | |
"label": "Enrollment Ticket", | |
"defaultValue": "", | |
"toolTip": "Enrollment ticket provided by administrator", | |
"constraints": { | |
"required": true | |
} | |
}, | |
{ | |
"name": "nodeConfig", | |
"type": "Microsoft.Common.TextBox", | |
"label": "Node Configuration", | |
"defaultValue": "{}", | |
"toolTip": "JSON configuration for Ockam node", | |
"constraints": { | |
"required": true | |
}, | |
"multiLine": true | |
} | |
] | |
} | |
], | |
"outputs": { | |
"vmName": "[basics('vmName')]", | |
"adminUsername": "[basics('adminUsername')]", | |
"adminPassword": "[basics('adminPassword')]", | |
"vmSize": "[steps('vmSettings').vmSize]", | |
"location": "[location()]", | |
"OSVersion": "[steps('vmSettings').osSettings.OSVersion]", | |
"virtualNetworkName": "[steps('vmSettings').networkSettings.vnetSelector.name]", | |
"virtualNetworkResourceGroupName": "[steps('vmSettings').networkSettings.vnetSelector.resourceGroup]", | |
"subnetName": "[steps('vmSettings').networkSettings.vnetSelector.subnets.subnet1.name]", | |
"nodeTicket": "[steps('ockamSettings').nodeTicket]", | |
"nodeConfig": "[steps('ockamSettings').nodeConfig]" | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", | |
"contentVersion": "1.0.0.0", | |
"parameters": { | |
"vmName": { | |
"type": "string", | |
"metadata": { | |
"description": "Name for the Virtual Machine" | |
} | |
}, | |
"adminUsername": { | |
"type": "string", | |
"metadata": { | |
"description": "Username for the Virtual Machine" | |
} | |
}, | |
"adminPassword": { | |
"type": "securestring", | |
"metadata": { | |
"description": "Password for the Virtual Machine" | |
} | |
}, | |
"vmSize": { | |
"type": "string", | |
"metadata": { | |
"description": "Size of the Virtual Machine" | |
} | |
}, | |
"location": { | |
"type": "string", | |
"defaultValue": "[resourceGroup().location]", | |
"metadata": { | |
"description": "Location for all resources" | |
} | |
}, | |
"OSVersion": { | |
"type": "string", | |
"metadata": { | |
"description": "The OS version for the VM" | |
} | |
}, | |
"virtualNetworkName": { | |
"type": "string", | |
"metadata": { | |
"description": "Name of the existing Virtual Network" | |
} | |
}, | |
"virtualNetworkResourceGroupName": { | |
"type": "string", | |
"metadata": { | |
"description": "Name of the resource group containing the Virtual Network" | |
} | |
}, | |
"subnetName": { | |
"type": "string", | |
"metadata": { | |
"description": "Name of the existing Subnet within the Virtual Network" | |
} | |
}, | |
"nodeTicket": { | |
"type": "string", | |
"metadata": { | |
"description": "Ticket parameter for the user data script" | |
} | |
}, | |
"nodeConfig": { | |
"type": "string", | |
"metadata": { | |
"description": "Configuration parameter for the user data script" | |
} | |
} | |
}, | |
"variables": { | |
"networkInterfaceName": "[concat(parameters('vmName'), '-nic')]", | |
"publicIPAddressName": "[concat(parameters('vmName'), '-pip')]", | |
"osDiskName": "[concat(parameters('vmName'), '-osdisk')]", | |
"imagePublisher": "RedHat", | |
"imageOffer": "RHEL", | |
"subnetRef": "[resourceId(parameters('virtualNetworkResourceGroupName'), 'Microsoft.Network/virtualNetworks/subnets', parameters('virtualNetworkName'), parameters('subnetName'))]", | |
"userDataScript": "[replace(replace(variables('userDataScriptTemplate'), '{nodeTicket}', parameters('nodeTicket')), '{nodeConfig}', parameters('nodeConfig'))]", | |
"userDataScriptTemplate": "#!/bin/bash\nset -ex\n\n# Define parameters\nTICKET=\"{nodeTicket}\"\nCONFIG='{nodeConfig}'\n\n# Install Ockam Command\nif ! curl --proto '=https' --tlsv1.2 -sSfL https://install.command.ockam.io | bash; then\n echo \"ERROR: Failed to install Ockam Command\"\n exit 1\nfi\nsource \"$HOME/.ockam/env\"\n\n# Verify Ockam installation\nif ! ockam --version; then\n echo \"ERROR: Ockam installation verification failed\"\n exit 1\nfi\n\necho \"Setup ockam with ticket: $TICKET\"\nexport OCKAM_LOG_MAX_FILES=5\nexport OCKAM_HOME=/opt/ockam_home\n\n# Create the Ockam configuration file\ncat << EOF > /opt/ockam.json\n$CONFIG\nEOF\n\n# View config file\ncat /opt/ockam.json\n\n# Create ockam node\nockam node create /opt/ockam.json --enrollment-ticket \"$TICKET\"\n\necho \"Ockam node setup completed successfully\"" | |
}, | |
"resources": [ | |
{ | |
"type": "Microsoft.Network/publicIPAddresses", | |
"apiVersion": "2021-02-01", | |
"name": "[variables('publicIPAddressName')]", | |
"location": "[parameters('location')]", | |
"properties": { | |
"publicIPAllocationMethod": "Dynamic", | |
"dnsSettings": { | |
"domainNameLabel": "[toLower(concat(parameters('vmName'), '-', uniqueString(resourceGroup().id)))]" | |
} | |
} | |
}, | |
{ | |
"type": "Microsoft.Network/networkInterfaces", | |
"apiVersion": "2021-02-01", | |
"name": "[variables('networkInterfaceName')]", | |
"location": "[parameters('location')]", | |
"dependsOn": [ | |
"[resourceId('Microsoft.Network/publicIPAddresses', variables('publicIPAddressName'))]" | |
], | |
"properties": { | |
"ipConfigurations": [ | |
{ | |
"name": "ipconfig1", | |
"properties": { | |
"privateIPAllocationMethod": "Dynamic", | |
"publicIPAddress": { | |
"id": "[resourceId('Microsoft.Network/publicIPAddresses', variables('publicIPAddressName'))]" | |
}, | |
"subnet": { | |
"id": "[variables('subnetRef')]" | |
} | |
} | |
} | |
] | |
} | |
}, | |
{ | |
"type": "Microsoft.Compute/virtualMachines", | |
"apiVersion": "2021-03-01", | |
"name": "[parameters('vmName')]", | |
"location": "[parameters('location')]", | |
"dependsOn": [ | |
"[resourceId('Microsoft.Network/networkInterfaces', variables('networkInterfaceName'))]" | |
], | |
"properties": { | |
"hardwareProfile": { | |
"vmSize": "[parameters('vmSize')]" | |
}, | |
"osProfile": { | |
"computerName": "[parameters('vmName')]", | |
"adminUsername": "[parameters('adminUsername')]", | |
"adminPassword": "[parameters('adminPassword')]" | |
}, | |
"storageProfile": { | |
"imageReference": { | |
"publisher": "[variables('imagePublisher')]", | |
"offer": "[variables('imageOffer')]", | |
"sku": "[parameters('OSVersion')]", | |
"version": "latest" | |
}, | |
"osDisk": { | |
"name": "[variables('osDiskName')]", | |
"createOption": "FromImage", | |
"managedDisk": { | |
"storageAccountType": "Premium_LRS" | |
} | |
} | |
}, | |
"networkProfile": { | |
"networkInterfaces": [ | |
{ | |
"id": "[resourceId('Microsoft.Network/networkInterfaces', variables('networkInterfaceName'))]" | |
} | |
] | |
}, | |
"diagnosticsProfile": { | |
"bootDiagnostics": { | |
"enabled": true | |
} | |
} | |
} | |
}, | |
{ | |
"type": "Microsoft.Compute/virtualMachines/extensions", | |
"apiVersion": "2021-03-01", | |
"name": "[concat(parameters('vmName'), '/CustomScriptExtension')]", | |
"location": "[parameters('location')]", | |
"dependsOn": [ | |
"[resourceId('Microsoft.Compute/virtualMachines', parameters('vmName'))]" | |
], | |
"properties": { | |
"publisher": "Microsoft.Azure.Extensions", | |
"type": "CustomScript", | |
"typeHandlerVersion": "2.1", | |
"autoUpgradeMinorVersion": true, | |
"protectedSettings": { | |
"script": "[base64(variables('userDataScript'))]" | |
} | |
} | |
} | |
], | |
"outputs": { | |
"vmName": { | |
"type": "string", | |
"value": "[parameters('vmName')]" | |
}, | |
"hostname": { | |
"type": "string", | |
"value": "[reference(resourceId('Microsoft.Network/publicIPAddresses', variables('publicIPAddressName'))).dnsSettings.fqdn]" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment