This articles assume you have a good working knowledge of ARM linked templates.
Background: I am deploying a SQL Server resource arm template through a linked template. I want to get the values of the output of this linked template to pass into as values into properties of the azure website resource in the main arm template.
In the main arm template, I am trying to deploy an Azure web site and reference the certain property values of the deployed sql server resource. I need the sql server FQDN to configure the web site connection string. I assume the sql server resource is deployed as this web site has set a dependsOn dependency this sql server resource.
"properties": { "DefaultConnection": { "value": "[concat('Data Source=tcp:', reference(concat('Microsoft.Sql/servers/', variables('sqlserverName'))).fullyQualifiedDomainName, ',1433;Initial Catalog=', variables('databaseName'), ';User Id=', parameters('sqlAdministratorLogin'), '@', reference(concat('Microsoft.Sql/servers/', variables('sqlserverName'))).fullyQualifiedDomainName, ';Password=', parameters('sqlAdministratorLoginPassword'), ';')]", } }
My wrong assumption was that I was thinking that I can possibly reference as follows:
reference(concat(‘Microsoft.Sql/servers/’, variables(‘sqlserverName’)))
Error upon deployment,
Invalid Template … Deployment template validation failed: ‘The resource referenced in output is not defined in the template
Resolution:
In the linked template output, return the values that is needed in the main template needs to make reference to the output of the linked template.
The proper approach is as follows:
"properties": { "DefaultConnection": { "value": "[concat('Data Source=tcp:', reference('linkedTemplate-sqlserver').outputs.dbfqdn.value, ',1433;Initial Catalog=', variables('databaseName'), ';User Id=', parameters('sqlAdministratorLogin'), '@', reference('linkedTemplate-sqlserver').outputs.dbfqdn.value,';Password=', parameters('sqlAdministratorLoginPassword'), ';')]", "type": "SQLAzure" } }
For further background readings