资源未在模板中定义

时间:2017-04-18 21:07:55

标签: azure templates arm-template azure-template

在模板下面部署:

https://gist.github.com/rnkhouse/aea0a8fd395da37b19466348b919d620

错误:

  

"部署失败,状态码为:400,消息:部署模板验证失败:'资源' Microsoft.Network/virtualNetworks/mtes-dev-VNET'未在模板中定义。有关使用详情,请参阅https://aka.ms/arm-template。'。"

我已经在其他模板中创建了虚拟网络,并在此处使用相同的资源组。但是,我仍然犯了错误。请指教!

3 个答案:

答案 0 :(得分:18)

删除代码中的dependsOn Vnet,只有当该资源是模板的一部分时才需要它,而不是已经部署过的。

答案 1 :(得分:3)

对于通过搜索“资源未在模板中定义”而最终在此处结束的任何人,,此错误消息的另一个可能原因是对以下形式的引用:

reference('<some complete id outside this template>')

listkeys('<some complete id outside this template>')

该错误消息不会告诉您,但是在引用当前模板之外定义的资源时,您需要包括API版本。

例如

reference('<some complete id outside this template>', '2018-03-01')

答案 2 :(得分:0)

我遇到这个问题,寻找相同的错误代码。但是,我有一个不同的问题:我正在引用模板中另一个资源的子资源。我想那些被认为不在当前模板之内。

例如

{
    "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json",
    "contentVersion": "1.0.0.0",
    "resources": [    
        {
            "type": "Microsoft.Network/virtualNetworks",
            "name": "vnetName",
            "location": "[resourceGroup().location]",
            "apiVersion": "2018-11-01",
            "properties": {
                ...
                }
            },
            "resources": [
                {
                    "type": "subnets",
                    "apiVersion": "2018-11-01",
                    "name": "subnetName",
                    "dependsOn": [
                        "[resourceId('Microsoft.Network/virtualNetworks', vnetName)]"
                    ],
                    "properties": {
                        ...
                    }
                }
            }
        },
        {
            "apiVersion": "2016-02-01",
            "name": "deploymentName",
            "type": "Microsoft.Resources/deployments",
            "dependsOn": [
                "[resourceId('Microsoft.Network/virtualNetworks.subnets', vnetName, subnetName)]"
            ],
        }
    ]
}

解决方法是将父资源放入部署中并依靠它。

例如

{
    "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json",
    "contentVersion": "1.0.0.0",
    "resources": [    
        {
            "apiVersion": "2016-02-01",
            "name": "deployment1",
            "type": "Microsoft.Resources/deployments",
            "resources": [
                {
                    "type": "Microsoft.Network/virtualNetworks",
                    "name": "vnetName",
                    "location": "[resourceGroup().location]",
                    "apiVersion": "2018-11-01",
                    "properties": {
                        ...
                    },
                    "resources": [
                        {
                            "type": "subnets",
                            "apiVersion": "2018-11-01",
                            "name": "subnetName",
                            "dependsOn": [
                                "[resourceId('Microsoft.Network/virtualNetworks', vnetName)]"
                            ],
                            "properties": {
                                ...
                            }
                        }
                    ]
                }
            ]
        },
        {
            "apiVersion": "2016-02-01",
            "name": "deployment2",
            "type": "Microsoft.Resources/deployments",
            "dependsOn": [
                "deployment1"
            ],
        }
    ]
}