Azure Resource Manager Template Language – resourceId(): Unable to evaluate template language function ‘resource Id’

Question:

How do you correctly call the function resourceId() defined in the Azure Resource Manager Template Language?

Context

This line in the template (see full template below)
"sourceDatabaseId": "[resourceId('Microsoft.Sql/servers/databases', 'TestDB')]"

Gives this error when running the PowerShell New-AzureResourceGroup CmdLet:

The function resourceId() has, according to the documentation, 2 parameters, and I call it with two constant strings that I beleve is correct:
resourceId('Microsoft.Sql/servers/databases', 'TestDB')
Still it produces an error message indicating that the number of parameters is wrong:
'Unable to evaluate template language function 'resource Id': the type 'Microsoft.Sql/servers/databases' requires '2' resource name argument(s).'

The resource used, according to the error message, is:
'/subscriptions/xxxxxxxx/resourceGroups/psResourceGroup/providers/Microsoft.Sql/servers/xxx-sql-server-name-xxx/databases/psDatabaseName'

So, what is the correct way to call resourceId() for a database?

Also, if I remove createMode and sourceDatabaseId from the template everything works fine.

This is the template used above

Answer:

I stumbled upon the solution in a completely unrelated article, but you should be passing

[resourceId('Microsoft.SQL/servers/databases', parameters('sqlServerName'), 'TestDB')]

Source:

Azure Resource Manager Template Language – resourceId(): Unable to evaluate template language function ‘resource Id’ by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply