首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >嵌套模板之间的Azure ARM依赖关系

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

Stack Overflow用户
提问于 2017-06-24 22:23:15
回答 1查看 2.4K关注 0票数 1

我创建了一个包含两个嵌套模板的模板。第一个嵌套模板将SQL服务器定义为:

代码语言:javascript
复制
{
  "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"
      }
    }
  ]
}

第二个嵌套模板定义了一个将托管在上述服务器上的数据库:

代码语言:javascript
复制
{
  "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')]"
  }
}

然后我的父模板看起来如下:

代码语言:javascript
复制
 {
  "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服务器,因此它不是命名问题。

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-06-25 06:34:06

为这些资源创建嵌套模板是完全没有意义的,但如果要这样做,则应该在模板中定义实际的嵌套模板调用以相互依赖(因此第二个嵌套模板应该取决于第一个模板),而不是在嵌套模板中的资源

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

好的,您的模板包含另一个bug,如果不指定api版本,您就不能使用引用函数对不在同一模板中的资源使用引用函数。

代码语言:javascript
复制
"[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版本的情况下使用引用函数。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44741476

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档