Lets say we have 2 linked arm templates with their associated *.params.json
files:
createAppServiceTemplate.json
createAppServiceTemplate.params.json
createSqlDbTemplate.json
createSqlDbTemplate.params.json
The second template createSqlDbTemplate.json
has outputs:
"outputs": {
"connectionString": {
"type": "string",
"value": "[concat('Database=', parameters('databaseName'), ';Server=', reference(resourceId('Microsoft.DBforPostgreSQL/servers',parameters('serverName')), '2017-12-01').fullyQualifiedDomainName, ';User Id=', parameters('administratorLogin'),'@', parameters('serverName'),';Password=', parameters('administratorPassword'))]"
}
}
I wan't to extract this output variable and pass it as parameter to createAppServiceTemplate.params.json
.
I have tried to add this to my :
"parameters": {
"usersDbConnectionString": {
"value": "[reference('createSqlDbTemplate').outputs.connectionString.value]"
}
}
But I think parameters can't evaluate expressions? How can I achieve the desired behaviour ?
Assuming you had the linked createSqlServerTemplate.json
template below:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {},
"variables": {},
"resources": [],
"outputs": {
"greetingMessage": {
"value": "Hello World",
"type" : "string"
}
}
}
The main template deploys the linked template and gets the returned value. Notice that it references the deployment resource by name, and it uses the name of the property returned by the linked template.
main-template.json
:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {},
"variables": {},
"resources": [
{
"type": "Microsoft.Resources/deployments",
"apiVersion": "2019-10-01",
"name": "createAppServiceTemplate",
"properties": {
"mode": "Incremental",
"templateLink": {
"uri": "[uri(deployment().properties.templateLink.uri, 'createAppServiceTemplate.json')]",
"contentVersion": "1.0.0.0"
},
"parameters": {
"userDbConnectionString: {
value: "[reference('createSqlServerTemplate').outputs.greetingMessage.value]"
}
}
}
},
{
"type": "Microsoft.Resources/deployments",
"apiVersion": "2019-10-01",
"name": "createSqlServerTemplate",
"properties": {
"mode": "Incremental",
"templateLink": {
"uri": "[uri(deployment().properties.templateLink.uri, 'createSqlServerTemplate.json')]",
"contentVersion": "1.0.0.0"
}
}
}
]
}