Azure ARM依赖于数据库子句

6qqygrtg  于 2022-12-14  发布在  其他
关注(0)|答案(2)|浏览(107)

我在ARM中有以下资源

{
    "name": "[parameters('dbServerName')]",
    "type": "Microsoft.Sql/servers",
    "location": "[resourceGroup().location]",
    "tags": {
      "displayName": "SqlServer"
    },
    "apiVersion": "2014-04-01-preview",
    "properties": {
      "administratorLogin": "[parameters('dbuser')]",
      "administratorLoginPassword": "[parameters('dbpassword')]",
      "version": "12.0"
    },
    "resources": [
      {
        "name": "[parameters('dbName')]",
        "type": "databases",
        "location": "[resourceGroup().location]",
        "tags": {
          "displayName": "[parameters('dbName')]"
        },
        "apiVersion": "2014-04-01-preview",
        "dependsOn": [
          "[parameters('dbServerName')]"
        ],
        "properties": {
          "edition": "[parameters('edition')]",
          "collation": "[parameters('collation')]",
          "maxSizeBytes": "[parameters('maxSizeBytes')]",
          "requestedServiceObjectiveName": "[parameters('requestedServiceObjectiveName')]"
        }
      },
      {
        "name": "[parameters('hivedbName')]",
        "type": "databases",
        "location": "[resourceGroup().location]",
        "tags": {
          "displayName": "[parameters('hivedbName')]"
        },
        "apiVersion": "2014-04-01-preview",
        "dependsOn": [
          "[parameters('dbServerName')]"
        ],
        "properties": {
          "edition": "[parameters('edition')]",
          "collation": "[parameters('collation')]",
          "maxSizeBytes": "[parameters('maxSizeBytes')]",
          "requestedServiceObjectiveName": "[parameters('requestedServiceObjectiveName')]"
        }
      },
      {
        "name": "[parameters('ooziedbName')]",
        "type": "databases",
        "location": "[resourceGroup().location]",
        "tags": {
          "displayName": "[parameters('ooziedbName')]"
        },
        "apiVersion": "2014-04-01-preview",
        "dependsOn": [
          "[parameters('dbServerName')]"
        ],
        "properties": {
          "edition": "[parameters('edition')]",
          "collation": "[parameters('collation')]",
          "maxSizeBytes": "[parameters('maxSizeBytes')]",
          "requestedServiceObjectiveName": "[parameters('requestedServiceObjectiveName')]"
        }
      },
      {
        "type": "firewallrules",
        "apiVersion": "2014-04-01-preview",
        "dependsOn": [
          "[parameters('dbServerName')]"
        ],
        "location": "[resourceGroup().location]",
        "name": "AllowAllWindowsAzureIps",
        "properties": {
          "endIpAddress": "0.0.0.0",
          "startIpAddress": "0.0.0.0"
        }
      }
    ]
  },

我想有另一个资源依赖以上,所以我尝试添加以下在我的下一个资源的依赖

[concat('Microsoft.Sql/servers,'/',parameters('dbServerName'),'/databases/',parameters('hivedbName'))]

但出现以下错误:

New-AzureRmResourceGroupDeployment : 4:46:59 PM - Error: Code=InvalidTemplate; Message=Deployment template validation failed: 'Circular dependency detected on resource: '/subscriptions/######/resourceGroups/QA/providers/Microsoft.Sql/servers/sparkqa/databases/SparkQAHive'.

然后我试着

"dependsOn": [
      "[concat('Microsoft.Sql/servers/', parameters('dbServerName'))]",
      "[concat('Microsoft.Sql/servers,'/',parameters('dbServerName'),'/databases/',parameters('hivedbName'))]"

    ],

但是,即使在创建concat('Microsoft.Sql/servers,'/',parameters('dbServerName'),'/databases/',parameters('hivedbName'))之前,它仍然会开始部署资源
下面是完整的模板https://paste.fedoraproject.org/454465/14767382/raw/
有人知道这里出了什么问题吗?

vngu2lb8

vngu2lb81#

您应该依赖于实际资源,而不仅仅是sql server名称:

"dependsOn": [
                "[concat('Microsoft.Sql/servers/', parameters('serverName'))]"
            ],
5sxhfpxr

5sxhfpxr2#

矿井现工作井用以下格式:
"dependsOn": ["[resourceId('Microsoft.Sql/servers/databases', variables('serverName'), variables('dbName'))]"],

相关问题