Hello
I understand that you want to validate whether a resource exists already before deploying an ARM template within the JSON.
ARM Templates cannot do that. You have to find a new method
For the provide code :
In the following ARM template, if the 'newOrExisting' parameter is set to 'new', then the storage account will be created. If it is set to 'existing', the storage account will not be created.
json
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"storageAccountName": {
"type": "string"
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]"
},
"newOrExisting": {
"type": "string",
"defaultValue": "new",
"allowedValues": [
"new",
"existing"
]
}
},
"resources": [
{
"condition": "[equals(parameters('newOrExisting'), 'new')]",
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2022-09-01",
"name": "[parameters('storageAccountName')]",
"location": "[parameters('location')]",
"sku": {
"name": "Standard_LRS"
},
"kind": "StorageV2"
}
],
"outputs": {
"storageAccountId": {
"type": "string",
"value": "[resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName'))]"
}
}
}
I hope this helps!
Kindly mark the answer as Accepted and Upvote in case it helped!
Regards