I will explain an error I encountered and my fix that I find worthwhile sharing and hope that it will save others some time.
In my ARM template development, I am trying to deploy an Azure SQL Server PaaS resource and Key Vault. This is so that I can store the DB admin password in the key vault as a secret. The below ARM template snippet results in the following deployment error.
Code : InvalidTemplate
Message : Deployment template validation failed: ‘The template reference ‘rkfunctionapp-keyvault’ is not valid: could not find template resource or resource copy with this name. Please see https://aka.ms/arm-template-expressions/#reference for usage details.
This error occurs when I deploy the template or test the deployment.
Test-AzureRmResourceGroupDeployment -ResourceGroupName $resourceGroupName -TemplateFile .\arm-functionapp-sql-main.json -TemplateParameterFile .\armdeploy-functionappsql.paramaters.json
I troubleshooted long and hard. I even referenced the documentation
Resolve errors for invalid template without much help.
The fix was to remove keyvaultName dependency
My intention with this was so that the key vault resource would be provisioned prior to the SQL Server resource. The error is correct in stating ‘The template reference ‘rkfunctionapp-keyvault’ is not valid: could not find template resource or resource copy with this name.’ because it had not been created yet.
So the lesson learned is that other syntax can refer to a resource such as dependsOn as opposed to the reference function. So keep an open mind and eyes peeled as this error message is quite vague at times.