I have a VM deloyment template where i am defining the VM size as T-Shirt Sizes for example small = Standard_DS2_v2, medium = Standard_E4s_v3 and large = Standard_E4s_v3.
I have defined them as an array as shown below in variables section
"parameters": {
"vmSpecs": {
"type": "array"
}
},
"variables": {
"vmSizeType" :[{
"small" : "Standard_DS2_v2",
"medium": "Standard_E4s_v3",
"large" : "Standard_E32s_v3"
}]
},
"resources": [
{
"name": "[parameters('vmSpecs')[copyIndex()].vmName]",
"type": "Microsoft.Compute/virtualMachines",
"location": "[resourceGroup().location]",
"apiVersion": "2018-06-01",
"dependsOn": [
"VMNIC0Copy",
"[variables('storageAccountName')]"
],
"copy": {
"name": "VMCopy",
"count": "[length(parameters('vmSpecs'))]"
},
"properties": {
"licenseType": "[parameters('vmSpecs')[copyIndex()].licenseType]",
"hardwareProfile": {
"vmSize": "[parameters('vmSpecs')variables('vmSizeType')[copyIndex()].vmSize[1]]"
}
}
In parameters file
"vmSpecs": {
"value": [
{ //vm01
"vmName": "test",
"dnsDomain": "domain.com",
"vmSize": "medium"
}
}
My question is how do i input vmSize and it selects the size based on what that has been defined
like you normally would (using dot notation) access object properties in almost any language:
"vmSizeType" :{ << should be an object, you only make it harder making it an array
"small" : "Standard_DS2_v2",
"medium": "Standard_E4s_v3",
"large" : "Standard_E32s_v3"
}
...
"vmSize": "[variables('vmSizeType')[parameters('vmSpecs')[copyIndex()].vmSize]]"
^^ tshirt variable ^ ^^ input parameter ^^ iteration ^^ property
^ get property defined dynamically, have to use [] syntax instead of dot notation
for static\hardcoded property name you can use dot notation:
variables('vmSizeType').small
if you need tshirt variable to be array (no reason), you'd have to account for that as well
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.