为什么 azure 子网没有 subnet.id 参数
why azure subnets don't have subnet.id param
我有以下生成 3 个子网的简单代码:
$resourceGroupName = "Test1"
$location = "West Europe"
$VNetName = "Test-VM"
$VNetIPRange = "192.168.0.0/21"
$SubnetAName = "SubA"
$SubnetAIPRange = "192.168.0.0/24"
$SubnetBName = "SubB"
$SubnetBIPRange = "192.168.1.0/24"
$SubnetCName = "SubC"
$SubnetCIPRange = "192.168.2.0/24"
New-AzResourceGroup -name $resourceGroupName -Location $location -Verbose
# subnets & vnet
$subnets = New-AzVirtualNetworkSubnetConfig `
-Name $SubnetAName `
-AddressPrefix $SubnetAIPRange `
-Verbose
$vnet = New-AzVirtualNetwork `
-Name $VNetName `
-AddressPrefix $VNetIPRange `
-Subnet $subnets `
-ResourceGroupName $resourceGroupName `
-Location $location `
-Verbose
Add-AzVirtualNetworkSubnetConfig `
-VirtualNetwork $vnet `
-Name $SubnetBName `
-AddressPrefix $SubnetBIPRange `
-Verbose
Add-AzVirtualNetworkSubnetConfig `
-VirtualNetwork $vnet `
-Name $SubnetCName `
-AddressPrefix $SubnetCIPRange `
-Verbose
Set-AzVirtualNetwork `
-VirtualNetwork $vnet `
-Verbose
代码 运行 成功并生成了预期的内容,但有一点除外。只有 SubA 有完整的信息。对于子网 B 和 C,只有以下配置如下:
{
"Name": "SubB",
"AddressPrefix": [
"192.168.1.0/24"
]
}
因此,我无法像这样引用子网 ID:
-SubnetId $vnet.Subnets[1].Id `
因为字段是空的:(
代码有问题还是我应该引用不同的子网 ID?
我想将一些虚拟机放在不同的子网中,但只有 SubA 在我 运行 上面的代码之后有 SubnetID。
{
"Delegations": [],
"Name": "SubA",
"Etag": "W/\"01baac3e-3fc3-400b-a6f1-64b08f5b45e7\"",
"Id": "/subscriptions/XXX/resourceGroups/Test1/providers/Microsoft.Network/virtua
lNetworks/Test-VM/subnets/SubA",
"AddressPrefix": [
"192.168.0.0/24"
],
"IpConfigurations": [],
"ServiceAssociationLinks": [],
"ResourceNavigationLinks": [],
"ServiceEndpoints": [],
"ServiceEndpointPolicies": [],
"InterfaceEndpoints": [],
"ProvisioningState": "Succeeded"
},
我测试了你的代码,我可以重现你的问题,只需在你的代码后面使用Get-AzVirtualNetwork
,然后你就可以得到其他两个子网的Id
。
$vnet = Get-AzVirtualNetwork -ResourceGroupName $resourceGroupName -Name $VNetName
$vnet.Subnets[1].Id
$vnet.Subnets[2].Id
我有以下生成 3 个子网的简单代码:
$resourceGroupName = "Test1"
$location = "West Europe"
$VNetName = "Test-VM"
$VNetIPRange = "192.168.0.0/21"
$SubnetAName = "SubA"
$SubnetAIPRange = "192.168.0.0/24"
$SubnetBName = "SubB"
$SubnetBIPRange = "192.168.1.0/24"
$SubnetCName = "SubC"
$SubnetCIPRange = "192.168.2.0/24"
New-AzResourceGroup -name $resourceGroupName -Location $location -Verbose
# subnets & vnet
$subnets = New-AzVirtualNetworkSubnetConfig `
-Name $SubnetAName `
-AddressPrefix $SubnetAIPRange `
-Verbose
$vnet = New-AzVirtualNetwork `
-Name $VNetName `
-AddressPrefix $VNetIPRange `
-Subnet $subnets `
-ResourceGroupName $resourceGroupName `
-Location $location `
-Verbose
Add-AzVirtualNetworkSubnetConfig `
-VirtualNetwork $vnet `
-Name $SubnetBName `
-AddressPrefix $SubnetBIPRange `
-Verbose
Add-AzVirtualNetworkSubnetConfig `
-VirtualNetwork $vnet `
-Name $SubnetCName `
-AddressPrefix $SubnetCIPRange `
-Verbose
Set-AzVirtualNetwork `
-VirtualNetwork $vnet `
-Verbose
代码 运行 成功并生成了预期的内容,但有一点除外。只有 SubA 有完整的信息。对于子网 B 和 C,只有以下配置如下:
{
"Name": "SubB",
"AddressPrefix": [
"192.168.1.0/24"
]
}
因此,我无法像这样引用子网 ID:
-SubnetId $vnet.Subnets[1].Id `
因为字段是空的:(
代码有问题还是我应该引用不同的子网 ID?
我想将一些虚拟机放在不同的子网中,但只有 SubA 在我 运行 上面的代码之后有 SubnetID。
{
"Delegations": [],
"Name": "SubA",
"Etag": "W/\"01baac3e-3fc3-400b-a6f1-64b08f5b45e7\"",
"Id": "/subscriptions/XXX/resourceGroups/Test1/providers/Microsoft.Network/virtua
lNetworks/Test-VM/subnets/SubA",
"AddressPrefix": [
"192.168.0.0/24"
],
"IpConfigurations": [],
"ServiceAssociationLinks": [],
"ResourceNavigationLinks": [],
"ServiceEndpoints": [],
"ServiceEndpointPolicies": [],
"InterfaceEndpoints": [],
"ProvisioningState": "Succeeded"
},
我测试了你的代码,我可以重现你的问题,只需在你的代码后面使用Get-AzVirtualNetwork
,然后你就可以得到其他两个子网的Id
。
$vnet = Get-AzVirtualNetwork -ResourceGroupName $resourceGroupName -Name $VNetName
$vnet.Subnets[1].Id
$vnet.Subnets[2].Id