我创建了一个包含两个嵌套模板的模板。第一个嵌套模板将SQL服务器定义为:
{
"name": "[variables('sqlServerName')]",
"type": "Microsoft.Sql/servers",
"location": "[resourceGroup().location]",
"apiVersion": "2014-04-01-preview",
"dependsOn": [],
"tags": {
"displayName": "SqlServer"
},
"properties": {
"administratorLogin": "[parameters('sqlAdministratorLogin')]",
"administratorLoginPassword": "[parameters('adminLoginPassword')]"
},
"resources": [
{
"name": "AllowAllWindowsAzureIps",
"type": "firewallrules",
"location": "[resourceGroup().location]",
"apiVersion": "2014-04-01-preview",
"dependsOn": [
"[resourceId('Microsoft.Sql/servers', variables('sqlServerName'))]"
],
"properties": {
"startIpAddress": "0.0.0.0",
"endIpAddress": "0.0.0.0"
}
}
]
}第二个嵌套模板定义了一个将托管在上述服务器上的数据库:
{
"name": "[concat(parameters('sqlServerName'), '/', 'Admin')]",
"type": "Microsoft.Sql/servers/databases",
"location": "[resourceGroup().location]",
"apiVersion": "2014-04-01-preview",
"dependsOn": [],
"tags": {
"displayName": "AdminApiDb"
},
"properties": {
"collation": "[parameters('AdminApiDbCollation')]",
"edition": "[parameters('AdminApiDbEdition')]",
"maxSizeBytes": "1073741824",
"requestedServiceObjectiveName": "[parameters('AdminApiDbRequestedServiceObjectiveName')]"
}
}然后我的父模板看起来如下:
{
"name": "Shared",
"type": "Microsoft.Resources/deployments",
"apiVersion": "2016-09-01",
"dependsOn": [],
"properties": {
"mode": "Incremental",
"templateLink": {
"uri": "[concat(parameters('_artifactsLocation'), '/', variables('SharedTemplateFolder'), '/', variables('SharedTemplateFileName'), parameters('_artifactsLocationSasToken'))]",
"contentVersion": "1.0.0.0"
}
},
{
"name": "Admin",
"type": "Microsoft.Resources/deployments",
"apiVersion": "2016-09-01",
"dependsOn": [
"[concat('Microsoft.Resources/deployments/', 'Shared')]"
],
"properties": {
"mode": "Incremental",
"templateLink": {
"uri": "[concat(parameters('_artifactsLocation'), '/', variables('AdminTemplateFolder'), '/', variables('AdminTemplateFileName'), parameters('_artifactsLocationSasToken'))]",
"contentVersion": "1.0.0.0"
}
}但是,当尝试部署此it错误时,请使用:
在模板中没有定义资源'Microsoft.Sql/servers/mysqlserver‘。
如何才能将其带到数据库中,以查看同级模板中的sql服务器?它确实使用正确的名称部署了sql服务器,因此它不是命名问题。
谢谢
发布于 2017-06-25 06:34:06
为这些资源创建嵌套模板是完全没有意义的,但如果要这样做,则应该在父模板中定义实际的嵌套模板调用以相互依赖(因此第二个嵌套模板应该取决于第一个模板),而不是在嵌套模板中的资源。
您只能对模板中的资源使用dependsOn,而这些资源不在模板中。
好的,您的模板包含另一个bug,如果不指定api版本,您就不能使用引用函数对不在同一模板中的资源使用引用函数。
"[concat('Data Source=tcp:', reference(concat('Microsoft.Sql/servers/', parameters('sqlserverName')), '2014-04-01-preview').fullyQualifiedDomainName, ',1433;Initial Catalog=Admin', ';User Id=', parameters('sqlAdministratorLogin'), '@', reference(concat('Microsoft.Sql/servers/', parameters('sqlserverName')), '2014-04-01-preview').fullyQualifiedDomainName, ';Password=', parameters('sqlAdministratorLoginPassword'), ';')]",如果资源位于同一个模板中,则可以在不使用api版本的情况下使用引用函数。
https://stackoverflow.com/questions/44741476
复制相似问题