Skip to content

Instantly share code, notes, and snippets.

@jimontheriver
Last active October 12, 2017 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimontheriver/9206070f6219af4b9b72e016315b04b1 to your computer and use it in GitHub Desktop.
Save jimontheriver/9206070f6219af4b9b72e016315b04b1 to your computer and use it in GitHub Desktop.
A simple Azure ARM template illustrating use of the uniqueName function.
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"type": "string",
"defaultValue": "centralus"
},
"virtualMachineSize": {
"type": "string",
"defaultValue": "Standard_A1_v2"
},
"adminUsername": {
"type": "string"
},
"adminPassword": {
"type": "securestring"
},
"virtualNetworkResourceGroupName": {
"type": "string"
},
"virtualNetworkName": {
"type": "string"
},
"subnetName": {
"type": "string",
"defaultValue": "Subnet"
},
"networkSecurityGroupName": {
"type": "string"
}
},
"variables": {
"vnetId": "[resourceId(parameters('virtualNetworkResourceGroupName'),'Microsoft.Network/virtualNetworks', parameters('virtualNetworkName'))]",
"subnetRef": "[concat(variables('vnetId'), '/subnets/', parameters('subnetName'))]",
"virtualMachineName": "[concat('vm', uniqueString(resourceGroup().id, deployment().name))]",
"networkInterfaceName": "[concat(variables('virtualMachineName'), '_nic')]",
"numberOfDataDisks": 2,
"sizeOfDataDisksInGb": 31,
"diskCaching": "ReadWrite"
},
"resources": [
{
"name": "[variables('virtualMachineName')]",
"type": "Microsoft.Compute/virtualMachines",
"apiVersion": "2016-04-30-preview",
"location": "[parameters('location')]",
"dependsOn": [
"[concat('Microsoft.Network/networkInterfaces/', variables('networkInterfaceName'))]"
],
"properties": {
"osProfile": {
"computerName": "[variables('virtualMachineName')]",
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPassword')]"
},
"hardwareProfile": {
"vmSize": "[parameters('virtualMachineSize')]"
},
"storageProfile": {
"imageReference": {
"publisher": "Canonical",
"offer": "UbuntuServer",
"sku": "16.04-LTS",
"version": "latest"
},
"osDisk": {
"createOption": "fromImage",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"copy": [
{
"name": "dataDisks",
"count": "[variables('numberOfDataDisks')]",
"input": {
"caching": "[variables('diskCaching')]",
"diskSizeGB": "[variables('sizeOfDataDisksInGb')]",
"lun": "[copyIndex('dataDisks')]",
"name": "[concat(variables('virtualMachineName'), '-datadisk', copyIndex('dataDisks'))]",
"createOption": "Empty",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
}
}
]
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces', variables('networkInterfaceName'))]"
}
]
}
}
},
{
"name": "[variables('networkInterfaceName')]",
"type": "Microsoft.Network/networkInterfaces",
"apiVersion": "2016-09-01",
"location": "[parameters('location')]",
"dependsOn": [
"[concat('Microsoft.Network/networkSecurityGroups/', parameters('networkSecurityGroupName'))]"
],
"properties": {
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": {
"subnet": {
"id": "[variables('subnetRef')]"
},
"privateIPAllocationMethod": "Dynamic"
}
}
],
"networkSecurityGroup": {
"id": "[resourceId('Microsoft.Network/networkSecurityGroups', parameters('networkSecurityGroupName'))]"
}
}
},
{
"name": "[parameters('networkSecurityGroupName')]",
"type": "Microsoft.Network/networkSecurityGroups",
"apiVersion": "2017-06-01",
"location": "[parameters('location')]",
"properties": {
"securityRules": [
{
"name": "default-allow-ssh",
"properties": {
"priority": 1000,
"protocol": "TCP",
"access": "Allow",
"direction": "Inbound",
"sourceAddressPrefix": "*",
"sourcePortRange": "*",
"destinationAddressPrefix": "*",
"destinationPortRange": "22"
}
}
]
}
}
],
"outputs": {
"adminUsername": {
"type": "string",
"value": "[parameters('adminUsername')]"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment