我花了几天时间尝试找出如何使用 Bicep 将路由表链接到子网。我在网上找到的与此相关的文档数量为零。显然,以前已经这样做过 - 但我做错了什么?
resource virtualNetwork 'Microsoft.Network/virtualNetworks@2019-11-01' = {
name: 'coolname'
location: resourceGroup().location
properties: {
addressSpace: {
addressPrefixes: [
'10.156.0.0/15'
]
}
subnets: [
{
name: 'CloudGuardExternal'
properties: {
addressPrefix: '10.156.0.0/24'
routeTable: // <---------- LOOK HERE
}
}
]
}
}
resource routeTableNumberOne 'Microsoft.Network/routeTables@2020-11-01' = {
name: 'routelol'
location: 'australiaeast'
properties: {
disableBgpRoutePropagation: false
routes: [
{
name: 'dropPacketTestRoute'
properties: {
addressPrefix: '10.0.0.0/8'
nextHopType: 'None'
hasBgpOverride: false
}
}
]
}
}
我已经创建了一个资源组。在其中创建了一个子网。我还创建了一个路由表,其中包含示例路由。
我花了几天时间试图找出如何填写routeTable属性。我没有收到错误 - 什么也没有发生。没有错误,当我部署代码时,门户上没有显示任何内容。
更新
subnets: [
{
name: 'CloudGuardExternal'
properties: {
addressPrefix: '10.156.0.0/24'
routeTable: routeTableNumberOne
}
}
]
我通过 CLI 命令而不是管道尝试了上述操作,这次我收到一条错误消息
{"status":"Failed","error":{"code":"DeploymentFailed","message":"At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/DeployOperations for usage details.","details":[{"code":"BadRequest","message":"{\r\n "error": {\r\n "code": "InvalidRequestFormat",\r\n
"message": "Cannot parse the request.",\r\n "details": [\r\n {\r\n "code": "MissingJsonReferenceId",\r\n
"message": "Value for reference id is missing. Path properties.subnets[0].properties.routeTable."\r\n }\r\n ]\r\n }\r\n}"}]}}
这对我来说确实是个好消息,因为至少我现在有一个错误!
更新#2
subnets: [
{
name: 'CloudGuardExternal'
properties: {
addressPrefix: '10.156.0.0/24'
routeTable: routeTableNumberOne.properties.routes[0]
}
}
]
我尝试了上面的方法,这次得到了不同的错误消息:
{"status":"Failed","error":{"code":"DeploymentFailed","message":"At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/DeployOperations for usage details.","details":[{"code":"BadRequest","message":"{\r\n "error": {\r\n "code": "InvalidRequestFormat",\r\n
"message": "Cannot parse the request.",\r\n "details": [\r\n {\r\n "code": "InvalidJsonReferenceWrongType",\r\n
"message": "Reference Id /subscriptions/ee8bbd18-7563-42cd-b616-53841d3f3b28/resourceGroups/hub/providers/Microsoft.Network/routeTables/routelol/routes/dropPacketTestRoute is referencing resource of a wrong type. The Id is expected to reference resources of type routeTables. Path properties.subnets[0].properties.routeTable."\r\n }\r\n ]\r\n }\r\n}"}]}}
更新#3
我尝试了以下方法
subnets: [
{
name: 'CloudGuardExternal'
properties: {
addressPrefix: '10.156.0.0/24'
routeTable: {
properties: {
routes: [
{
properties: {
addressPrefix: '10.0.0.0/8'
nextHopType: 'None'
}
}
]
}
}
}
}
]
但这一次,收到以下错误消息
{"status":"Failed","error":{"code":"DeploymentFailed","message":"At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/DeployOperations for usage details.","details":[{"code":"BadRequest","message":"{\r\n "error": {\r\n "code": "InvalidRequestFormat",\r\n
"message": "Cannot parse the request.",\r\n "details": [\r\n {\r\n "code": "MissingJsonReferenceId",\r\n
"message": "Value for reference id is missing. Path properties.subnets[0].properties.routeTable."\r\n }\r\n ]\r\n }\r\n}"}]}}
更新4
subnets: [
{
name: 'CloudGuardExternal'
properties: {
addressPrefix: '10.156.0.0/24'
routeTable: {
id: 'nameonecool'
properties: {
routes: [
{
properties: {
addressPrefix: '10.0.0.0/8'
nextHopType: 'None'
}
}
]
}
}
}
}
]
现在,我收到此错误:
{"status":"Failed","error":{"code":"DeploymentFailed","message":"At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/DeployOperations for usage details.","details":[{"code":"BadRequest","message":"{\r\n "error": {\r\n "code": "LinkedInvalidPropertyId",\r\n
"message": "Property id 'nameonecool' at path 'properties.subnets[0].properties.routeTable.id' is invalid. Expect fully qualified resource Id that start with '/subscriptions/{subscriptionId}' or '/providers/{resourceProviderNamespace}/'."\r\n }\r\n}"}]}}
好吧,至少这个错误看起来很独特!
最佳答案
您必须像这样使用resourceId。
subnets: {
name: subnet.name
properties: {
addressPrefix: subnet.addressPrefix
routeTable: {
id: resourceId(subnet.routeTable.resourceGroup, 'Microsoft.Network/routeTables', subnet.routeTable.name) ?? null
}
}
}]
关于amazon-web-services - 如何将路由表链接到Azure Bicep中的子网?给出的代码示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71026556/