简体   繁体   English

使用 Azure CLI 将 VNET 链接到私有 DNS

[英]Azure link VNET to Private DNS with Azure CLI

I'm working on an Azure CLI script to automate the creation of a vnet in our cloud infrastructure.我正在使用 Azure CLI 脚本来自动在我们的云基础架构中创建 vnet。 One of the parts in this script is linking a VNET to a Azure Private DNS.此脚本中的一个部分是将 VNET 链接到 Azure 私有 DNS。 This should be easy, but apperently the difficulty is the fact that the VNET and the Private DNS are in a different resourcegroup.这应该很容易,但显然困难在于 VNET 和私有 DNS 位于不同的资源组中。

This is my script;这是我的脚本;

   az network private-dns link vnet create --name MyLink \
     --registration-enabled true \
     --resource-group my-vnet-resourcegroup\
     --subscription 'My Subscription' \
     --tags Domain=MyDomain \
     --virtual-network my-own-vnet \
     --zone-name myzone.nu

Now when exuting i'm getting the following error;现在,当退出时,我收到以下错误;

Can not perform requested operation on nested resource.无法对嵌套资源执行请求的操作。 Parent resource 'myzone.nu' not found.未找到父资源“myzone.nu”。

So I updated the script to look at the resourcegroup for the private DNS;所以我更新了脚本以查看私有 DNS 的资源组;

   az network private-dns link vnet create --name MyLink \
     --registration-enabled true \
     --resource-group my-privatedns-resourcegroup \
     --subscription 'My Subscription' \
     --tags Domain=MyDomain \
     --virtual-network my-own-vnet \
     --zone-name myzone.nu

This gives me the following error;这给了我以下错误;

Deployment failed.部署失败。 Correlation ID: (SomeGuid).关联 ID:(SomeGuid)。 Virtual network resource not found for '/subscriptions//resourceGroups/my-privatedns-resourcegroup/providers/Microsoft.Network/virtualNetworks/my-own-vnet'找不到“/subscriptions//resourceGroups/my-privatedns-resourcegroup/providers/Microsoft.Network/virtualNetworks/my-own-vnet”的虚拟网络资源

I'm quite stuck at the moment on how to fix this.我现在很困惑如何解决这个问题。 Anybody else ran into this before?其他人以前遇到过这个吗? I'm open to suggestions!我愿意接受建议!

You could pass virtual network Id to the private DNS link vNet creation if the Virtual network is in another resource group which differs from your DNS zone resource group.如果虚拟网络位于与您的 DNS 区域资源组不同的另一个资源组中,您可以将虚拟网络 ID 传递给私有 DNS 链接 vNet 创建。

VnetID=$(az network vnet show -g vnet-rg -n my-vnet --query 'id' -o tsv)
az network private-dns link vnet create -n mylink -e true -g dns-rg -z myzone.nu -v $VnetID

在此处输入图片说明

or, you could use Azure Powershell .或者,您可以使用Azure Powershell

$vnet = Get-AzVirtualNetwork -name my-own-vnet -ResourceGroupName my-vnet-resourcegroup

New-AzPrivateDnsVirtualNetworkLink -ZoneName private.contoso.com `
  -ResourceGroupName MyAzureResourceGroup -Name "mylink" `
  -VirtualNetworkId $vnet.id -EnableRegistration

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM