Microsoft.Network/networkInterfaces资源的创建失败,并且嵌套臂模板中的请求错误

问题描述 投票:0回答:1

我正在尝试部署到嵌套模板,在该模板中,我正在创建一个具有两个子网和一个网络接口卡的虚拟网络。尽管虚拟网络创建成功,但是网络接口卡创建失败,并且部署错误显示以下消息。

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "rgPrefix": {
            "type": "string"
        },
        "location": {
            "type": "string"
        }
    },
    "variables": {
        "rgName": "[parameters('rgPrefix')]",
        "VNet": "[concat(variables('rgName'), '-Vnet')]",
        "vmName": "[concat(variables('rgName'), 'Vm1')]",
        "networkInterfaceName": "[concat(variables('vmName'), 'nic1')]"
    },
    "resources": [
        {
            "type": "Microsoft.Resources/resourceGroups",
            "apiVersion": "2018-05-01",
            "location": "[parameters('location')]",
            "name": "[variables('rgName')]",
            "properties": {
            }
        },
        {
            "type": "Microsoft.Resources/deployments",
            "apiVersion": "2017-05-10",
            "name": "vmDeployment",
            "resourceGroup": "[variables('rgName')]",
            "dependsOn": [
                "[resourceId('Microsoft.Resources/resourceGroups/', variables('rgName'))]"
            ],
            "properties": {
                "expressionEvaluationOptions": {
                    "scope": "outer"
                },
                "mode": "Incremental",
                "template": {
                    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
                    "contentVersion": "1.0.0.0",
                    "resources": [
                        {
                            "type": "Microsoft.Network/virtualNetworks",
                            "name": "[variables('VNet')]",
                            "apiVersion": "2019-11-01",
                            "location": "[parameters('location')]",
                            "tags": {
                                "displayName": "[variables('VNet')]"
                            },
                            "properties": {
                                "addressSpace": {
                                    "addressPrefixes": [
                                        "10.0.0.0/16"
                                    ]
                                },
                                "subnets": [
                                    {
                                        "name": "subnet-1",
                                        "properties": {
                                            "addressPrefix": "10.0.0.0/24"
                                        }
                                    },
                                    {
                                        "name": "subnet-2",
                                        "properties": {
                                            "addressPrefix": "10.0.1.0/24"
                                        }
                                    }
                                ]
                            },
                            "resources": [
                                {
                                    "type": "subnets",
                                    "apiVersion": "2019-11-01",
                                    "name": "subnet-1",
                                    "dependsOn": [
                                        "[resourceId('Microsoft.Network/virtualNetworks', variables('VNet'))]"
                                    ],
                                    "properties": {
                                        "addressPrefix": "10.0.0.0/24",
                                        "delegations": [
                                        ],
                                        "privateEndpointNetworkPolicies": "Enabled",
                                        "privateLinkServiceNetworkPolicies": "Enabled"
                                    }
                                },
                                {
                                    "type": "subnets",
                                    "apiVersion": "2019-11-01",
                                    "name": "subnet-2",
                                    "dependsOn": [
                                        "[resourceId('Microsoft.Network/virtualNetworks', variables('VNet'))]"
                                    ],
                                    "properties": {
                                        "addressPrefix": "10.0.1.0/24",
                                        "delegations": [
                                        ],
                                        "privateEndpointNetworkPolicies": "Enabled",
                                        "privateLinkServiceNetworkPolicies": "Enabled"
                                    }
                                }
                            ]
                        },
                        {
                            "name": "[variables('networkInterfaceName')]",
                            "type": "Microsoft.Network/networkInterfaces",
                            "apiVersion": "2019-07-01",
                            "location": "[parameters('location')]",
                            "dependsOn": [
                            ],
                            "properties": {
                                "ipConfigurations": [
                                    {
                                        "name": "ipconfig1",
                                        "properties": {
                                            "privateIpAddressVersion": "IPv4",
                                            "privateIPAllocationMethod": "Dynamic",
                                            "subnet": {
                                                "id": "[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('VNet'), 'subnet-1')]"
                                            }
                                        }
                                    }
                                ]
                            }
                        }

                    ],
                    "outputs": {
                    }
                }
            }
        }
    ],
    "outputs": {
}
}

运行部署时,出现以下错误

Resource Microsoft.Network/networkInterfaces 'vssRGVm1nic1' failed with message '{   "error": {     "code": "InvalidRequestFormat",    
     | "message": "Cannot parse the request.
azure arm-template
1个回答
0
投票

错误来自resourceId()功能的使用。在订阅级别的部署上,它的行为有所不同。您应该将其替换为concat函数:

"[concat(subscription().id, '/resourceGroups/', variables('rgName'), '/providers/Microsoft.Network/virtualNetworks/', variables('VNet'), '/subnets/subnet-1')]"

https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/template-functions-resource#return-value-5

© www.soinside.com 2019 - 2024. All rights reserved.