当前位置: 首页 > 知识库问答 >
问题:

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

郎翔
2023-03-14

我正在尝试创建一个ARM模板,该模板创建两个资源组,然后部署VNET并在它们之间创建对等。模板中的vNet对等资源不工作。我一直收到相同的错误,我相信这是因为我正在尝试使用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')]"
                                        }
                                    }
                                ]
                            }
                        }
                    ]
                }
            }
        }
    ]
}

这就是我收到的错误

新AzureRmDeployment:16:13:36-资源Microsoft。Network/virtualNetworks/virtualNetworkPeerings'DMZ-VNET/peered to HUB VNET'失败,html" target="_blank">消息为“{”error:{”code:“ResourceNotFound”,“message:“未找到资源组“HUB-RG”下的资源“Microsoft.Network/virtualNetworks/DMZ-VNET”。}”第1行:1个字符:1个新AzureRmDeployment-名称$jobname-位置$location-TemplatePar…~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~CategoryInfo:NotSpecified:(:)[New AzureRmDeployment],Exception FullyQualifiedErrorId:Microsoft。蔚蓝色的命令。资源经理。cmdlet。实施
自动化。NewAzureDeploymentCmdlet

共有1个答案

袁康裕
2023-03-14

首先,你可以修改“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并将新部署的VNET与其他资源组中的现有VNET对等的Azure ARM模板? 请在下面找到JSON模板: {“$schema”:https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#,“内容版本”:“1.0。0.0", } 这就是我一直得到的错误:

  • 卡尔顿

  • 提前感谢,我是ARM模板的新手,还在学习它是如何工作的。我有一个包含资源的VNET,VNET地址空间是10.0。0.0/16,它包含一个子网,地址空间为10.0。0.0/16我正在尝试使用ARM模板更新DNS,它向我抛出了一个错误 这是我的部署文件 下面是我的参数文件 我不确定我做错了什么。 我尝试使用[]括号作为参数,并得到了错误信息 “{”代码“:”部署失败“,”消息“:”至少一个资源部署操作

  • 我有一个嵌套的对象 JSON 结构,如下所示; 我的输出CSV应该是这样的; {“name”:“Sydney”,“type”:“record”,“namespace”:”Sydney“,“fields”:[{“name:”Bikes“,“type:”{“type:“array”,“items”:{“name”:“Vehicle”,“type”:“record”,“field”:[{“name“:”

  • 问题内容: 我要返回一个Mongoose文档,并希望在发送之前向其中添加一些元数据。但是,我无法添加任何属性,我不确定为什么。我检查了它是否可以使用Object.isExtensible(doc)扩展。 可能是什么问题? 问题答案: 啊..我的对象是一个Mongoose文档,不允许添加属性。解决方案是将返回的文档转换为普通对象,或者在查询中调用lean()。

  • 我正在尝试将在GCP库伯内特斯引擎集群上运行的Java应用程序与Mongo Atlas集群(M20)连接起来。以前,当我没有打开VPC Peering并且我使用常规连接字符串时,它运行良好。但我现在正在尝试使用VPC Peering,在我的GCP项目中使用VPC网络。我按照https://docs.atlas.mongodb.com/security-vpc-peering/.中的步骤选择了192