繁体   English   中英

嵌套模板之间的Azure ARM依赖关系

[英]Azure ARM dependencies between nested templates

我创建了一个具有两个嵌套模板的模板。 第一个嵌套模板将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服务器,因此这不是命名问题。

谢谢

为这些资源创建嵌套模板绝对没有意义,但是,如果要这样做,则应将实际的嵌套模板调用定义为相互依赖(因此,第二个嵌套模板应取决于第一个)。 模板, 里面没有嵌套模板的资源。

您只能对模板中的资源使用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版本的引用函数

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM