无法将vNet对等添加到嵌套的ARM模板

时间:2019-01-08 16:25:14

标签: azure azure-resource-manager azure-virtual-network arm-template azure-template

我试图创建一个ARM模板,该模板创建2个资源组,然后部署vNet并在它们之间创建对等。模板中的vNet对等资源不起作用。我一直收到相同的错误,我相信这是因为我正在尝试创建一个与VNET建立对等关系的对等网络,该对等网络与我要部署到的VNET /资源组不在同一网络中。

我正在使用嵌套模板部署到单独的资源组中。

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/Microsoft.Resources.json",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "vnetName": {
            "type": "string",
            "metadata": {
                "description": "VNet name"
            }
        },
        "vnetAddressPrefix": {
            "type": "string",
            "metadata": {
                "description": "Address prefix"
            }
        },
        "DMZResourceGroup": {
            "type": "string",
            "metadata": {
                "description": "resource group for DMZ environment"
            }
        },
        "HUBResourceGroup": {
            "type": "string",
            "metadata": {
                "description": "resource group for HUB environment"
            }
        },
        "DMZvnet": {
            "type": "string",
            "metadata": {
                "description": "VNet for DMZ environment"
            }
        },
        "DMZvnetAddressPrefix": {
            "type": "string",
            "metadata": {
                "description": "DMZ VNet Address prefix"
            }
        },
        "DMZFESubnet1Prefix": {
            "type": "string",
            "metadata": {
                "description": "Subnet1 for DMZ environment. This is the Front-End subnet"
            }
        },
        "DMZBESubnet2Prefix": {
            "type": "string",
            "metadata": {
                "description": "Subnet1 for DMZ environment. This is the Back-End subnet"
            }
        },
        "DMZNSG": {
            "type": "string",
            "metadata": {
                "description": "NSG for DMZ environment"
            }
        },
        "DMZFEsubnetName": {
            "type": "string",
            "metadata": {
                "description": "Front-End subnet for DMZ environment"
            }
        },
        "DMZBEsubnetName": {
            "type": "string",
            "metadata": {
                "description": "Back-End subnet for DMZ environment"
            }
        },
        "subnet1Prefix": {
            "type": "string",
            "metadata": {
                "description": "Subnet 1 prefix"
            }
        },
        "subnet1Name": {
            "type": "string",
            "metadata": {
                "description": "Subnet 1 Name"
            }
        },
        "subnet2Prefix": {
            "type": "string",
            "metadata": {
                "description": "Subnet 2 Prefix"
            }
        },
        "subnet2Name": {
            "type": "string",
            "metadata": {
                "description": "Subnet 2 Name"
            }
        },
        "subnet3Prefix": {
            "type": "string",
            "metadata": {
                "description": "Subnet 3 Prefix"
            }
        },
        "subnet3Name": {
            "type": "string",
            "metadata": {
                "description": "Subnet 3 Name"
            }
        },
        "networkSecurityGroupName": {
            "type": "string"
        }
    },
    "variables": {
        "location": "West Europe",
        "HUBvNettoDMZvNet": "[concat(parameters('VNetName'), '-', parameters('DMZvnet'))]",
        "DMZvNettoHUBvNet": "[concat(parameters('DMZvnet'), '-', parameters('VNetName'))]"
    },
    "resources": [
        {
            "name": "[parameters('DMZResourceGroup')]",
            "type": "Microsoft.Resources/resourceGroups",
            "apiVersion": "2018-05-01",
            "location": "[variables('Location')]",
            "tags": {},
            "properties": {}
        },
        {
            "name": "[parameters('HUBResourceGroup')]",
            "type": "Microsoft.Resources/resourceGroups",
            "apiVersion": "2018-05-01",
            "location": "[variables('Location')]",
            "tags": {},
            "properties": {}
        },
        {
            "apiVersion": "2017-05-10",
            "name": "hubtemplate",
            "type": "Microsoft.Resources/deployments",
            "resourceGroup": "[parameters('Hubresourcegroup')]",
            "dependsOn": [
                "[resourceId('Microsoft.Resources/resourceGroups/', parameters('HUBResourceGroup'))]"
            ],
            "properties": {
                "mode": "incremental",
                "template": {
                    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
                    "contentversion": "1.0.0.0",
                    "parameters": {},
                    "variables": {},
                    "resources": [
                        {
                            "apiVersion": "2017-06-01",
                            "type": "Microsoft.Network/virtualNetworks",
                            "name": "[parameters('vnetName')]",
                            "location": "[variables('Location')]",
                            "properties": {
                                "addressSpace": {
                                    "addressPrefixes": [
                                        "[parameters('vnetAddressPrefix')]"
                                    ]
                                },
                                "subnets": [
                                    {
                                        "name": "[parameters('subnet1Name')]",
                                        "properties": {
                                            "addressPrefix": "[parameters('subnet1Prefix')]"
                                        }
                                    },
                                    {
                                        "name": "[parameters('subnet2Name')]",
                                        "properties": {
                                            "addressPrefix": "[parameters('subnet2Prefix')]"
                                        }
                                    },
                                    {
                                        "name": "[parameters('subnet3Name')]",
                                        "properties": {
                                            "addressPrefix": "[parameters('subnet3Prefix')]"
                                        }
                                    }
                                ]
                            }
                        },
                        {
                            "name": "[concat(parameters('dmzvnet'), '/peered-to-', parameters('vnetname'))]",
                            "type": "Microsoft.Network/virtualNetworks/virtualNetworkPeerings",
                            "apiVersion": "2018-08-01",
                            "location": "[variables('location')]",
                            "dependsOn": [
                                "[concat('Microsoft.Network/virtualNetworks/', parameters('VNetName'))]"
                            ],
                            "properties": {
                                "allowVirtualNetworkAccess": true,
                                "allowForwardedTraffic": true,
                                "allowGatewayTransit": true,
                                "useRemoteGateways": true,
                                "remoteVirtualNetwork": {
                                    "id": "/subscriptions/d01e22a2-bdb3-4c7a-92a2-613cc0dc1f30/resourceGroups/dmz-rg/providers/Microsoft.Network/virtualNetworks/dmz-vnet"
                                }
                            }
                        },
                        {
                            "apiVersion": "2015-06-15",
                            "type": "Microsoft.Network/networkSecurityGroups",
                            "name": "[parameters('networkSecurityGroupName')]",
                            "location": "[variables('location')]",
                            "properties": {
                                "securityRules": [
                                    {
                                        "name": "allow-rdp",
                                        "properties": {
                                            "description": "allow rdp",
                                            "protocol": "*",
                                            "sourcePortRange": "*",
                                            "destinationPortRange": "3389",
                                            "sourceAddressPrefix": "*",
                                            "destinationAddressPrefix": "10.0.1.0",
                                            "access": "Allow",
                                            "priority": 110,
                                            "direction": "Inbound"
                                        }
                                    },
                                    {
                                        "name": "allow-smb",
                                        "properties": {
                                            "description": "allow smb",
                                            "protocol": "*",
                                            "sourcePortRange": "*",
                                            "destinationPortRange": "445",
                                            "sourceAddressPrefix": "*",
                                            "destinationAddressPrefix": "10.0.2.0",
                                            "access": "Allow",
                                            "priority": 112,
                                            "direction": "Inbound"
                                        }
                                    }
                                ]
                            }
                        }
                    ]
                }
            }
        },
        {
            "apiVersion": "2017-05-10",
            "name": "dmztemplate",
            "type": "Microsoft.Resources/deployments",
            "resourceGroup": "[parameters('DMZresourcegroup')]",
            "dependsOn": [
                "[resourceId('Microsoft.Resources/resourceGroups/', parameters('DMZResourceGroup'))]"
            ],
            "properties": {
                "mode": "incremental",
                "template": {
                    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
                    "contentversion": "1.0.0.0",
                    "parameters": {},
                    "variables": {},
                    "resources": [
                        {
                            "apiVersion": "2017-06-01",
                            "type": "Microsoft.Network/virtualNetworks",
                            "name": "[parameters('DMZvNet')]",
                            "location": "[variables('Location')]",
                            "properties": {
                                "addressSpace": {
                                    "addressPrefixes": [
                                        "[parameters('DMZvNetaddressPrefix')]"
                                    ]
                                },
                                "subnets": [
                                    {
                                        "name": "[parameters('DMZFEsubnetName')]",
                                        "properties": {
                                            "addressPrefix": "[parameters('DMZFESubnet1Prefix')]"
                                        }
                                    },
                                    {
                                        "name": "[parameters('DMZBEsubnetName')]",
                                        "properties": {
                                            "addressPrefix": "[parameters('DMZBESubnet2Prefix')]"
                                        }
                                    }
                                ]
                            }
                        }
                    ]
                }
            }
        }
    ]
}

这是我收到的错误

  

New-AzureRmDeployment:16:13:36-资源   Microsoft.Network/virtualNetworks/virtualNetworkPeerings   “ DMZ-VNET /对等HUB-VNET”失败,并显示消息“ {“错误”:{       “ code”:“ ResourceNotFound”,       “消息”:“资源组下的资源'Microsoft.Network/virtualNetworks/DMZ-VNET'   找不到“ HUB-RG”。“}}'在第1行:char:1   + New-AzureRmDeployment-名称$ jobname-位置$ location -TemplatePar ...   + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~       + CategoryInfo:未指定:(:) [New-AzureRmDeployment],异常       + FullyQualifiedErrorId:Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implement
  ation.NewAzureDeploymentCmdlet

1 个答案:

答案 0 :(得分:0)

首先,您可以在任何地方修改"outputs": {},它们并没有真正添加任何有用的内容,只是将模板打乱了:)。好的,这里有太多东西要进行介绍,不幸的是,这是一个有效的模板,您可以进行比较,找出问题所在。如果您需要回答一些问题,请在这里与我联系。

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/Microsoft.Resources.json",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "VNetName": {
            "type": "string",
            "metadata": {
                "description": "vnetname"
            }
        },
        "vnetAddressPrefix": {
            "type": "string",
            "metadata": {
                "description": "Address prefix"
            }
        },
        "DMZResourceGroup": {
            "type": "string",
            "metadata": {
                "description": "resource group for DMZ environment"
            }
        },
        "HUBResourceGroup": {
            "type": "string",
            "metadata": {
                "description": "resource group for HUB environment"
            }
        },
        "DMZvnet": {
            "type": "string",
            "metadata": {
                "description": "VNet for DMZ environment"
            }
        },
        "DMZvnetAddressPrefix": {
            "type": "string",
            "metadata": {
                "description": "DMZ VNet Address prefix"
            }
        },
        "DMZFESubnet1Prefix": {
            "type": "string",
            "metadata": {
                "description": "Subnet1 for DMZ environment. This is the Front-End subnet"
            }
        },
        "DMZBESubnet2Prefix": {
            "type": "string",
            "metadata": {
                "description": "Subnet1 for DMZ environment. This is the Back-End subnet"
            }
        },
        "DMZNSG": {
            "type": "string",
            "metadata": {
                "description": "NSG for DMZ environment"
            }
        },
        "DMZFEsubnetName": {
            "type": "string",
            "metadata": {
                "description": "Front-End subnet for DMZ environment"
            }
        },
        "DMZBEsubnetName": {
            "type": "string",
            "metadata": {
                "description": "Back-End subnet for DMZ environment"
            }
        },
        "subnet1Prefix": {
            "type": "string",
            "metadata": {
                "description": "Subnet 1 prefix"
            }
        },
        "subnet1Name": {
            "type": "string",
            "metadata": {
                "description": "Subnet 1 Name"
            }
        },
        "subnet2Prefix": {
            "type": "string",
            "metadata": {
                "description": "Subnet 2 Prefix"
            }
        },
        "subnet2Name": {
            "type": "string",
            "metadata": {
                "description": "Subnet 2 Name"
            }
        },
        "subnet3Prefix": {
            "type": "string",
            "metadata": {
                "description": "Subnet 3 Prefix"
            }
        },
        "subnet3Name": {
            "type": "string",
            "metadata": {
                "description": "Subnet 3 Name"
            }
        },
        "networkSecurityGroupName": {
            "type": "string"
        }
    },
    "variables": {
        "location": "West Europe",
        "HUBvNettoDMZvNet": "[concat(parameters('VNetName'), '-', parameters('DMZvnet'))]",
        "DMZvNettoHUBvNet": "[concat(parameters('DMZvnet'), '-', parameters('VNetName'))]"
    },
    "resources": [
        {
            "name": "[parameters('DMZResourceGroup')]",
            "type": "Microsoft.Resources/resourceGroups",
            "apiVersion": "2018-05-01",
            "location": "[variables('Location')]",
            "tags": {},
            "properties": {}
        },
        {
            "name": "[parameters('HUBResourceGroup')]",
            "type": "Microsoft.Resources/resourceGroups",
            "apiVersion": "2018-05-01",
            "location": "[variables('Location')]",
            "tags": {},
            "properties": {}
        },
        {
            "apiVersion": "2017-05-10",
            "name": "hubtemplate",
            "type": "Microsoft.Resources/deployments",
            "resourceGroup": "[parameters('Hubresourcegroup')]",
            "dependsOn": [
                "[resourceId('Microsoft.Resources/resourceGroups/', parameters('HUBResourceGroup'))]",
                "dmztemplate"
            ],
            "properties": {
                "mode": "incremental",
                "template": {
                    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
                    "contentversion": "1.0.0.0",
                    "parameters": {},
                    "variables": {},
                    "resources": [
                        {
                            "apiVersion": "2017-06-01",
                            "type": "Microsoft.Network/virtualNetworks",
                            "name": "[parameters('vnetName')]",
                            "location": "[variables('Location')]",
                            "properties": {
                                "addressSpace": {
                                    "addressPrefixes": [
                                        "[parameters('vnetAddressPrefix')]"
                                    ]
                                },
                                "subnets": [
                                    {
                                        "name": "[parameters('subnet1Name')]",
                                        "properties": {
                                            "addressPrefix": "[parameters('subnet1Prefix')]"
                                        }
                                    },
                                    {
                                        "name": "[parameters('subnet2Name')]",
                                        "properties": {
                                            "addressPrefix": "[parameters('subnet2Prefix')]"
                                        }
                                    },
                                    {
                                        "name": "[parameters('subnet3Name')]",
                                        "properties": {
                                            "addressPrefix": "[parameters('subnet3Prefix')]"
                                        }
                                    }
                                ]
                            }
                        },
                        {
                            "name": "[concat(parameters('vnetName'), '/peered-to-', parameters('vnetname'))]",
                            "type": "Microsoft.Network/virtualNetworks/virtualNetworkPeerings",
                            "apiVersion": "2018-08-01",
                            "location": "[variables('location')]",
                            "dependsOn": [
                                "[concat('Microsoft.Network/virtualNetworks/', parameters('VNetName'))]"
                            ],
                            "properties": {
                                "allowVirtualNetworkAccess": true,
                                "allowForwardedTraffic": true,
                                "allowGatewayTransit": true,
                                "useRemoteGateways": false,
                                "remoteVirtualNetwork": {
                                    "id": "[concat(subscription().id, '/resourceGroups/', parameters('DMZresourcegroup'), '/providers/Microsoft.Network/virtualNetworks/', parameters('DMZvNet'))]"
                                }
                            }
                        },
                        {
                            "apiVersion": "2015-06-15",
                            "type": "Microsoft.Network/networkSecurityGroups",
                            "name": "[parameters('networkSecurityGroupName')]",
                            "location": "[variables('location')]",
                            "properties": {
                                "securityRules": [
                                    {
                                        "name": "allow-rdp",
                                        "properties": {
                                            "description": "allow rdp",
                                            "protocol": "*",
                                            "sourcePortRange": "*",
                                            "destinationPortRange": "3389",
                                            "sourceAddressPrefix": "*",
                                            "destinationAddressPrefix": "10.0.1.0",
                                            "access": "Allow",
                                            "priority": 110,
                                            "direction": "Inbound"
                                        }
                                    },
                                    {
                                        "name": "allow-smb",
                                        "properties": {
                                            "description": "allow smb",
                                            "protocol": "*",
                                            "sourcePortRange": "*",
                                            "destinationPortRange": "445",
                                            "sourceAddressPrefix": "*",
                                            "destinationAddressPrefix": "10.0.2.0",
                                            "access": "Allow",
                                            "priority": 112,
                                            "direction": "Inbound"
                                        }
                                    }
                                ]
                            }
                        }
                    ]
                }
            }
        },
        {
            "apiVersion": "2017-05-10",
            "name": "dmztemplate",
            "type": "Microsoft.Resources/deployments",
            "resourceGroup": "[parameters('DMZresourcegroup')]",
            "dependsOn": [
                "[resourceId('Microsoft.Resources/resourceGroups/', parameters('DMZResourceGroup'))]"
            ],
            "properties": {
                "mode": "incremental",
                "template": {
                    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
                    "contentversion": "1.0.0.0",
                    "parameters": {},
                    "variables": {},
                    "resources": [
                        {
                            "apiVersion": "2017-06-01",
                            "type": "Microsoft.Network/virtualNetworks",
                            "name": "[parameters('DMZvNet')]",
                            "location": "[variables('Location')]",
                            "properties": {
                                "addressSpace": {
                                    "addressPrefixes": [
                                        "[parameters('DMZvNetaddressPrefix')]"
                                    ]
                                },
                                "subnets": [
                                    {
                                        "name": "[parameters('DMZFEsubnetName')]",
                                        "properties": {
                                            "addressPrefix": "[parameters('DMZFESubnet1Prefix')]"
                                        }
                                    },
                                    {
                                        "name": "[parameters('DMZBEsubnetName')]",
                                        "properties": {
                                            "addressPrefix": "[parameters('DMZBESubnet2Prefix')]"
                                        }
                                    }
                                ]
                            }
                        }
                    ]
                }
            }
        }
    ]
}
订阅级部署中的

resourceId():https://docs.microsoft.com/en-us/azure/azure-resource-manager/deploy-to-subscription#using-template-functions

ps。我确定您在两个vnet上都需要对等。