'Pass Array value to a Variable
I'd like to variablise one element of an Array parameter that I'm passing to a Bicep template. Here's a cut down version of the Parameter file:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"value": "uksouth"
},
"networkSecurityGroupRules": {
"value": [
{
"name": "RDP",
"properties": {
"priority": 300,
"protocol": "TCP",
"access": "Allow",
"direction": "Inbound",
"sourceAddressPrefix": "*",
"sourcePortRange": "*",
"destinationAddressPrefix": "*",
"destinationPortRange": "3389"
}
}
]
},
"vnetName": {
"value": "Dtldevopsagent"
},
"subnetName": {
"value": "sandbox_subnet_2"
},
"virtualMachineName": {
"value": "test-db"
},
"osDiskType": {
"value": "Premium_LRS"
},
"dataDisks": {
"value": [
{
"lun": 0,
"createOption": "attach",
"caching": "ReadOnly",
"writeAcceleratorEnabled": false,
"id": null,
"name": "[concat(parameters('virtualMachineName'), '-_DataDisk_0')]'",
"storageAccountType": null,
"diskSizeGB": null,
"diskEncryptionSet": null
},
{
"lun": 1,
"createOption": "attach",
"caching": "None",
"writeAcceleratorEnabled": false,
"id": null,
"name": "[concat(parameters('virtualMachineName'),'-DataDisk_1')]",
"storageAccountType": null,
"diskSizeGB": null,
"diskEncryptionSet": null
}
]
},
"dataDiskResources": {
"value": [
{
"name": "[concat(parameters('virtualMachineName'),'-DataDisk_0')]",
"sku": "Premium_LRS",
"properties": {
"diskSizeGB": 32,
"creationData": {
"createOption": "empty"
}
}
},
{
"name": "[concat(parameters('virtualMachineName'),'-DataDisk_1')]",
"sku": "Premium_LRS",
"properties": {
"diskSizeGB": 32,
"creationData": {
"createOption": "empty"
}
}
}
]
},
}
}
The Array parameter values I'm trying to set are dataDisks.value.name and dataDiskResources.value.name. I tried using "[concat(parameters('virtualMachineName'), '-_DataDisk_0')]'" in order to set the Virtual Machine disk's name, but I got an error "The value of parameter disk.name is invalid.".
Is there a way I can pass these values to a Variable in my Bicep template file and only edit the "name" value of each of these two parameters? Or is there another way I can edit it?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
