将虚拟网络添加到现有事件中心命名空间
Add virtual network to existing Event hub namespace
我有一个 arm 模板可以将新的虚拟网络添加到现有的事件中心命名空间。
问题是我必须硬编码,或者要求 vnet 和子网地址前缀作为参数。
有没有办法不必执行此操作或提取这些值并在模板上使用?
Vnet 存在子网存在
使用参考函数为我获取值,但如果我在资源定义中使用它,我会收到循环定义错误。
尝试使用引用函数获取 vnet 和子网的 ip,但我无法在参数或变量中使用它,在资源中我收到循环依赖错误。
基本上我喜欢在一个干净的模板上做这个。
"variables": {
"namespaceVirtualNetworkRuleName": "[concat(parameters('eventhubNamespaceName'), concat('/', parameters('vnetRuleName')))]",
"subNetId": "[resourceId('Microsoft.Network/virtualNetworks/subnets/', parameters('vnetRuleName'), parameters('subnetName'))]"
},
resources : [
{
"apiVersion": "2018-01-01-preview",
"name": "[variables('namespaceVirtualNetworkRuleName')]",
"type": "Microsoft.EventHub/namespaces/VirtualNetworkRules",
"properties": {
"virtualNetworkSubnetId": "[variables('subNetId')]"
}
}
]
但我必须添加具有正确 IP 的 vnet 和子网才能正常工作。
"variables": {
"namespaceVirtualNetworkRuleName": "[concat(parameters('eventhubNamespaceName'), concat('/', parameters('vnetRuleName')))]",
"subNetId": "[resourceId('Microsoft.Network/virtualNetworks/subnets/', parameters('vnetRuleName'), parameters('subnetName'))]"
},
"resources": [
{
"apiVersion": "2018-01-01-preview",
"name": "[parameters('eventhubNamespaceName')]",
"type": "Microsoft.EventHub/namespaces",
"location": "[parameters('location')]",
"sku": {
"name": "Standard",
"tier": "Standard"
},
"properties": { }
},
{
"apiVersion": "2017-09-01",
"name": "[parameters('vnetRuleName')]",
"location": "[parameters('location')]",
"type": "Microsoft.Network/virtualNetworks",
"properties": {
"addressSpace": {
"addressPrefixes": [
"a.b.c.0/24",
"x.y.0.0/16"
]
},
"subnets": [
{
"name": "[parameters('subnetName')]",
"properties": {
"addressPrefix": "x.y.z.w/26",
"serviceEndpoints": [
{
"service": "Microsoft.EventHub"
}
]
}
}
]
}
},
{
"apiVersion": "2018-01-01-preview",
"name": "[variables('namespaceVirtualNetworkRuleName')]",
"type": "Microsoft.EventHub/namespaces/VirtualNetworkRules",
"dependsOn": [
"[concat('Microsoft.EventHub/namespaces/', parameters('eventhubNamespaceName'))]"
],
"properties": {
"virtualNetworkSubnetId": "[variables('subNetId')]"
}
}
]
关于如何删除 vnet 部分或在列表中获取模板之前的 ip 并将其作为参数传递的任何想法?
了解如何进行这项工作。
解决方案是这样的:
"variables": {
},
"resources": [
{
"apiVersion": "2018-01-01-preview",
"name": "[parameters('eventhubNamespaceName')]",
"type": "Microsoft.EventHub/namespaces",
"location": "[resourceGroup().location]",
"sku": {
"name": "Standard",
"tier": "Standard"
},
"properties": { }
},
{
"apiVersion": "2018-01-01-preview",
"name": "[concat(parameters('eventhubNamespaceName'), concat('/', parameters('vnetSubscriptioID'), parameters('vnetResorceGroupName'), parameters('vnetRuleName'), parameters('subnetName')[copyIndex('subnetcopy')]))]",
"type": "Microsoft.EventHub/namespaces/VirtualNetworkRules",
"location": "[resourceGroup().location]",
"dependsOn": [
"[concat('Microsoft.EventHub/namespaces/', parameters('eventhubNamespaceName'))]"
],
"properties": {
"virtualNetworkSubnetId": "[resourceId(parameters('vnetSubscriptioID'), parameters('vnetResorceGroupName'),'Microsoft.Network/virtualNetworks/subnets/', parameters('vnetRuleName'), parameters('subnetName')[copyIndex('subnetcopy')])]"
},
"copy": {
"name": "subnetcopy",
"count": "[length(parameters('subnetName'))]"
}
}
]
}
最后不需要网络部分。更新了我的解决方案,以便能够一次部署多个子网。
我有一个 arm 模板可以将新的虚拟网络添加到现有的事件中心命名空间。
问题是我必须硬编码,或者要求 vnet 和子网地址前缀作为参数。
有没有办法不必执行此操作或提取这些值并在模板上使用? Vnet 存在子网存在 使用参考函数为我获取值,但如果我在资源定义中使用它,我会收到循环定义错误。
尝试使用引用函数获取 vnet 和子网的 ip,但我无法在参数或变量中使用它,在资源中我收到循环依赖错误。
基本上我喜欢在一个干净的模板上做这个。
"variables": {
"namespaceVirtualNetworkRuleName": "[concat(parameters('eventhubNamespaceName'), concat('/', parameters('vnetRuleName')))]",
"subNetId": "[resourceId('Microsoft.Network/virtualNetworks/subnets/', parameters('vnetRuleName'), parameters('subnetName'))]"
},
resources : [
{
"apiVersion": "2018-01-01-preview",
"name": "[variables('namespaceVirtualNetworkRuleName')]",
"type": "Microsoft.EventHub/namespaces/VirtualNetworkRules",
"properties": {
"virtualNetworkSubnetId": "[variables('subNetId')]"
}
}
]
但我必须添加具有正确 IP 的 vnet 和子网才能正常工作。
"variables": {
"namespaceVirtualNetworkRuleName": "[concat(parameters('eventhubNamespaceName'), concat('/', parameters('vnetRuleName')))]",
"subNetId": "[resourceId('Microsoft.Network/virtualNetworks/subnets/', parameters('vnetRuleName'), parameters('subnetName'))]"
},
"resources": [
{
"apiVersion": "2018-01-01-preview",
"name": "[parameters('eventhubNamespaceName')]",
"type": "Microsoft.EventHub/namespaces",
"location": "[parameters('location')]",
"sku": {
"name": "Standard",
"tier": "Standard"
},
"properties": { }
},
{
"apiVersion": "2017-09-01",
"name": "[parameters('vnetRuleName')]",
"location": "[parameters('location')]",
"type": "Microsoft.Network/virtualNetworks",
"properties": {
"addressSpace": {
"addressPrefixes": [
"a.b.c.0/24",
"x.y.0.0/16"
]
},
"subnets": [
{
"name": "[parameters('subnetName')]",
"properties": {
"addressPrefix": "x.y.z.w/26",
"serviceEndpoints": [
{
"service": "Microsoft.EventHub"
}
]
}
}
]
}
},
{
"apiVersion": "2018-01-01-preview",
"name": "[variables('namespaceVirtualNetworkRuleName')]",
"type": "Microsoft.EventHub/namespaces/VirtualNetworkRules",
"dependsOn": [
"[concat('Microsoft.EventHub/namespaces/', parameters('eventhubNamespaceName'))]"
],
"properties": {
"virtualNetworkSubnetId": "[variables('subNetId')]"
}
}
]
关于如何删除 vnet 部分或在列表中获取模板之前的 ip 并将其作为参数传递的任何想法?
了解如何进行这项工作。 解决方案是这样的:
"variables": {
},
"resources": [
{
"apiVersion": "2018-01-01-preview",
"name": "[parameters('eventhubNamespaceName')]",
"type": "Microsoft.EventHub/namespaces",
"location": "[resourceGroup().location]",
"sku": {
"name": "Standard",
"tier": "Standard"
},
"properties": { }
},
{
"apiVersion": "2018-01-01-preview",
"name": "[concat(parameters('eventhubNamespaceName'), concat('/', parameters('vnetSubscriptioID'), parameters('vnetResorceGroupName'), parameters('vnetRuleName'), parameters('subnetName')[copyIndex('subnetcopy')]))]",
"type": "Microsoft.EventHub/namespaces/VirtualNetworkRules",
"location": "[resourceGroup().location]",
"dependsOn": [
"[concat('Microsoft.EventHub/namespaces/', parameters('eventhubNamespaceName'))]"
],
"properties": {
"virtualNetworkSubnetId": "[resourceId(parameters('vnetSubscriptioID'), parameters('vnetResorceGroupName'),'Microsoft.Network/virtualNetworks/subnets/', parameters('vnetRuleName'), parameters('subnetName')[copyIndex('subnetcopy')])]"
},
"copy": {
"name": "subnetcopy",
"count": "[length(parameters('subnetName'))]"
}
}
]
}
最后不需要网络部分。更新了我的解决方案,以便能够一次部署多个子网。