我正在使用此方法将 NATGateway 关联到子网。
ArmClient azure = this.azureProvider.GetAzureClient(resourceTenantId, subscriptionId);
var subnetId = SubnetResource.CreateResourceIdentifier(subscriptionId, resourceGroupName, vNetName, subnetName);
SubnetResource subnetResource = await azure.GetSubnetResource(subnetId).GetAsync();
subnetResource.Data.NatGatewayId = ResourceIdentifier.Parse(natGatewayId);
await subnetResource.UpdateAsync(waitUntil: WaitUntil.Completed, data: subnetResource.Data);
但我不知道如何解除关联。
解除关联,如果我使用
SubnetResource subnetResource = await azure.GetSubnetResource(subnetId).GetAsync();
subnetResource.Data.NatGatewayId = null;
await subnetResource.UpdateAsync(waitUntil: WaitUntil.Completed, data: subnetResource.Data);
Azure 将抛出异常 "error":{"code":"InvalidRequestFormat","message":"无法解析请求。","details":[{"code":"MissingJsonReferenceId","message":"Value缺少参考 ID。路径properties.natGateway。"}] 因为resourceId 不能为空。
如何使用 Azure SDK 取消子网与 NAT 网关的关联
根据此 MS-Document,可以通过 Azure 门户或使用 Azure CLI 命令取消子网与 NAT 网关的关联。
以下是用于取消子网与 NAT 网关关联的 Azure CLI 命令:
命令:
az network vnet subnet update --resource-group <resource-group-name> --name <subnet-name> --vnet-name <vnet-name> --nat-gateway null
输出:
az network vnet subnet update --resource-group vxxx --name xx --vnet-name vxxx --nat-gateway null
{
"addressPrefix": "10.xxx/24",
"delegations": [],
"etag": "W/\"1059xxx4092f\"",
"id": "/subscriptions/xxxx/resourceGroups/xxxx/providers/Microsoft.Network/virtualNetworks/vnet678/subnets/default",
"name": "default",
"networkSecurityGroup": {
"id": "/subscriptions/xxxx/resourceGroups/xxxx/providers/Microsoft.Network/networkSecurityGroups/sampnat",
"resourceGroup": "v-vsettu-mindtree"
},
"privateEndpointNetworkPolicies": "NetworkSecurityGroupEnabled",
"privateLinkServiceNetworkPolicies": "Enabled",
"provisioningState": "Succeeded",
"resourceGroup": "vxe",
"serviceEndpoints": [
{
"locations": [
"eastus",
"westus",
"westus3"
],
"provisioningState": "Succeeded",
"service": "Microsoft.Storage"
}
],
"type": "Microsoft.Network/virtualNetworks/subnets"
}
传送门:
参考: