嵌套模板之间的Azure臂依赖性



我创建了一个具有两个嵌套模板的模板。第一个嵌套模板将SQL Server定义为:

{
  "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"
    }
}

但是,当尝试部署此错误时,它会出现以下错误:

资源'Microsoft.sql/servers/mysqlserver'未在模板中定义。

如何将其转到数据库中以在同胞模板中查看SQL Server?它确实使用正确的名称部署了SQL Server,因此这不是命名问题。

谢谢

为这些资源创建嵌套模板绝对没有任何意义,但是如果您想这样做,则应定义实际的嵌套模板调用以相互依赖(所以第二嵌套模板应取决于第一个模板(在 parent 模板中,而不是内部的资源 nested模板。

您只能将dependsOn用于模板中的资源,而这些资源不在模板中。

好的,您的模板包含另一个错误,您不能在不指定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版本的参考函数

最新更新