假设我们有2个链接的手臂模板及其关联的*.params.json
文件:
createAppServiceTemplate.json
createAppServiceTemplate.params.json
createSqlDbTemplate.json
createSqlDbTemplate.params.json
第二个模板createSqlDbTemplate.json
具有输出:
"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'))]"
}
}
我将不提取此输出变量并将其作为参数传递给createAppServiceTemplate.params.json
。
我尝试将其添加到我的计算机中:
"parameters": {
"usersDbConnectionString": {
"value": "[reference('createSqlDbTemplate').outputs.connectionString.value]"
}
}
但是我认为参数不能计算表达式?如何实现所需的行为?
答案 0 :(得分:2)
假设您下面有链接的createSqlServerTemplate.json
模板:
{
"$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"
}
}
}
主模板部署链接的模板并获取返回的值。请注意,它按名称引用部署资源,并且使用链接模板返回的属性的名称。
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"
}
}
}
]
}