将新的NIC添加到现有子网

发布于 2025-01-29 14:14:33 字数 1443 浏览 3 评论 0原文

我有一个现有的VNET和子网,并且我正在尝试使用以下二头肌部署新的NIC向子网部署,

param location string = resourceGroup().location
param nicName string
param vNetName string
param subnetName string

resource vnet 'Microsoft.Network/virtualNetworks@2021-02-01' existing = {
  name: vNetName
  scope: resourceGroup('myRgName')
}

resource subnet 'Microsoft.Network/virtualNetworks/subnets@2021-02-01' existing = {
  parent: vnet
  name: subnetName
}

resource nsg 'Microsoft.Network/networkSecurityGroups@2021-08-01' = {
  name: '${nicName}-nsg'
  location: location
}

resource nic 'Microsoft.Network/networkInterfaces@2021-08-01' = {
  name: nicName
  location: location
  dependsOn: [
    subnet
  ]
  properties: {
    ipConfigurations: [
      {
        name: 'ipConfig'
        properties: {
          privateIPAllocationMethod: 'Dynamic'    
          subnet: subnet
          primary: true
          privateIPAddressVersion: 'IPv4'
        }
      }
    ]
    networkSecurityGroup: nsg
  }
}

我会编译模板并尝试部署,但我丢失了引用ID的错误值。 PATH属性。IpConfigurations[0] .properties.subnet。似乎是由手臂未找到子网引起的(存在的,我可以访问)。

json部分看起来像这样

"subnet": "[reference(extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, 'myRgName'), 'Microsoft.Network/virtualNetworks/subnets', split(parameters('subnetName'), '/')[0], split(parameters('subnetName'), '/')[1]), '2021-02-01', 'full')]",

I have an existing vNet and subnet and I'm trying to deploy a new NIC to the Subnet with the following bicep

param location string = resourceGroup().location
param nicName string
param vNetName string
param subnetName string

resource vnet 'Microsoft.Network/virtualNetworks@2021-02-01' existing = {
  name: vNetName
  scope: resourceGroup('myRgName')
}

resource subnet 'Microsoft.Network/virtualNetworks/subnets@2021-02-01' existing = {
  parent: vnet
  name: subnetName
}

resource nsg 'Microsoft.Network/networkSecurityGroups@2021-08-01' = {
  name: '${nicName}-nsg'
  location: location
}

resource nic 'Microsoft.Network/networkInterfaces@2021-08-01' = {
  name: nicName
  location: location
  dependsOn: [
    subnet
  ]
  properties: {
    ipConfigurations: [
      {
        name: 'ipConfig'
        properties: {
          privateIPAllocationMethod: 'Dynamic'    
          subnet: subnet
          primary: true
          privateIPAddressVersion: 'IPv4'
        }
      }
    ]
    networkSecurityGroup: nsg
  }
}

I compile the template and try to deploy but I'm getting the error Value for reference id is missing. Path properties.ipConfigurations[0].properties.subnet. which appears to be caused by the ARM not finding the subnet (which exists and I have access to).

The json portion of it looks like this

"subnet": "[reference(extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, 'myRgName'), 'Microsoft.Network/virtualNetworks/subnets', split(parameters('subnetName'), '/')[0], split(parameters('subnetName'), '/')[1]), '2021-02-01', 'full')]",

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

[旋木] 2025-02-05 14:14:33

用于

subnet: {
  id: subnet.id
}

NIC属性中的子网参考...如Thomas所述,您需要对NetworkSecurityGroup进行相同的操作。

Use

subnet: {
  id: subnet.id
}

for the subnet reference in the NIC's properties... you'll need the same for the networkSecurityGroup as Thomas mentioned.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文