Assistance with ARM template for Azure HCI Virtual Machine
Posted by Sin_of_the_Dark@reddit | sysadmin | View on Reddit | 0 comments
Hi all,
I'm working on an ARM template to generalize and automate deployment of virtual machines to our new HCI stack. I've almost gotten it nailed down, but am running into an odd issue. I mean, it may not be odd, but I am relatively new to working with ARM templates. Below is my template:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"name": {
"type": "string"
},
"location": {
"type": "string",
"defaultValue": "eastus"
},
"customLocationId": {
"type": "string",
"defaultValue": "{custom resourceId}",
"metadata": {
"description": "Resource ID of the CustomLocation"
}
},
"adminUsername": {
"type": "string"
},
"adminPassword": {
"type": "securestring"
},
"securityType": {
"type": "string",
"defaultValue": "Standard"
},
"keyData": {
"type": "securestring",
"defaultValue": "null",
"metadata": {
"description": "SSH public key certificate used to authenticate with the VM through ssh. The key needs to be at least 2048-bit and in ssh-rsa format."
}
},
"environment": {
"type": "string",
"allowedValues": [
"Sandbox",
"Dev",
"Test",
"Beta",
"Staging",
"Prod"
],
"metadata": {
"description": "Values here are restricted to those in the Value column. Use of other values will result in a failure to build/change the resource. Sandbox,Dev,Test,Beta,Staging,Prod,Prod2,DR,CMI,Upper, and Lower"
}
},
"countCPU":{
"type":"int",
"metadata": {
"description": "Number of vCPUs"
}
},
"sizeMB":{
"type":"int",
"metadata": {
"description": "RAM size in MB"
}
},
"ApplicationName": {
"type": "string"
},
"ProtectedData": {
"type": "string",
"allowedValues": [
"Yes",
"No"
]
},
"BillTo": {
"type": "string"
}
},
"resources": [
{
"type": "Microsoft.HybridCompute/machines",
"apiVersion": "2023-06-20-preview",
"name": "[parameters('name')]",
"kind": "HCI",
"location": "[parameters('location')]",
"identity": {
"type": "SystemAssigned"
},
"tags": {
"ApplicationName": "[parameters('ApplicationName')]",
"Environment": "[parameters('environment')]",
"ProtectedData": "[parameters('ProtectedData')]",
"BillTo": "[parameters('BillTo')]"
}
},
{
"name": "[parameters('name')]-nic",
"type": "Microsoft.AzureStackHCI/networkInterfaces",
"apiVersion": "2023-09-01-preview",
"location": "[parameters('location')]",
"extendedLocation": {
"type": "CustomLocation",
"name": "[parameters('customLocationId')]"
},
"properties": {
"ipConfigurations": [
{
"name": "[parameters('name')]-nic",
"properties": {
"gateway": "10.67.133.254",
"subnet": {
"id": "{custom resourceId}"
}
}
}
]
}
},
{
"type": "Microsoft.AzureStackHCI/VirtualMachineInstances",
"apiVersion": "2023-09-01-preview",
"scope": "[concat('Microsoft.HybridCompute/machines', '/', parameters('name'))]",
"name": "default",
"extendedLocation": {
"type": "CustomLocation",
"name": "[parameters('customLocationId')]"
},
"dependsOn": [
"[resourceId('Microsoft.HybridCompute/machines',parameters('name'))]",
"[resourceid('Microsoft.AzureStackHCI/networkInterfaces', concat(parameters('name'), '-nic'))]"
],
"properties": {
"osProfile": {
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPassword')]",
"computerName": "[parameters('name')]",
"linuxConfiguration": {
"provisionVMAgent": true,
"provisionVMConfigAgent": true,
"ssh": {
"publicKeys": [
{
"keyData": "[parameters('keyData')]",
"path": "[concat('/home/', parameters('adminUsername'), '/.ssh/authorized_keys')]"
}
]
},
"disablePasswordAuthentication": false
}
},
"hardwareProfile": {
"vmSize": "Default",
"processors": "[parameters('countCPU')]",
"memoryMB": "[parameters('sizeMB')]"
},
"storageProfile": {
"imageReference": {
"id": "{custom resourceId}"
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceid('Microsoft.AzureStackHCI/networkInterfaces', concat(parameters('name'), '-nic'))]"
}
]
}
}
}
]
}
However, when validating the template I get the following error:
>{"code":"InvalidTemplate","message":"Deployment template validation failed: 'The resource 'Microsoft.AzureStackHCI/networkInterfaces/MYPCNAME-nic' is not defined in the template. Please see https://aka.ms/arm-syntax for usage details.'."}
It's pretty clearly defined under networkProfile.networkInterfaces.id, so I'm wondering if maybe I'm using the wrong syntax for concat. I've ran it against GPT 4 and it couldn't find anything, not that it's ever very accurate lol
0 Comments