简体   繁体   English

将 API 管理私有 IP 地址输入私有 ZED5F2BDECBD4BD349FBZD09 的条目时,不应使用模板 function 'reference'

[英]The template function 'reference' is not expected when feeding API Management private IP addresses into private DNS entry with Bicep

I want to create DNS A records for my internal API Management instance in a private DNS zone azure-api.net along with the API Management deployment:我想在私有 DNS 区域azure-api.net中为我的内部 API 管理实例创建 DNS A 记录以及 ZDB974238714CA8ACE3FZ 管理部署:1714CA8ACE3FZA

var privateDnsZoneName = 'azure-api.net'
resource privateDnsZone 'Microsoft.Network/privateDnsZones@2020-06-01' = {
  name: privateDnsZoneName
  location: 'Global'
}

resource privateDnsZoneEntry 'Microsoft.Network/privateDnsZones/A@2020-06-01' = {
  name: apim.name
  parent: privateDnsZone
  properties: {
    aRecords: [for addr in apim.properties.privateIPAddresses: {
      ipv4Address: addr
    }]
    ttl: 3600
  }
}

However when deploying it results into this error:但是,在部署时会导致此错误:

Line |
  57 |  New-AzResourceGroupDeployment -ResourceGroupName $ResourceGroupName `
     |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | 17:12:13 - Error: Code=InvalidTemplate; Message=Deployment template validation failed: 'The template resource
     | '[format('{0}/{1}', variables('privateDnsZoneName'), parameters('apimName'))]' at line '221' and column '9' is not
     | valid: The template function 'reference' is not expected at this location. Please see
     | https://aka.ms/arm-template-expressions for usage details.. Please see https://aka.ms/arm-template-expressions for
     | usage details.'.

It seems that reference() function is not supported at this place (in ARM):似乎这个地方不支持reference() function(在ARM中):

{
  "type": "Microsoft.Network/privateDnsZones/A",
  "apiVersion": "2020-06-01",
  "name": "[format('{0}/{1}', variables('privateDnsZoneName'), parameters('apimName'))]",
  "properties": {
    "copy": [
      {
        "name": "aRecords",
        "count": "[length(reference(resourceId('Microsoft.ApiManagement/service', parameters('apimName'))).privateIPAddresses)]",
        "input": {
          "ipv4Address": "[reference(resourceId('Microsoft.ApiManagement/service', parameters('apimName'))).privateIPAddresses[copyIndex('aRecords')]]"
        }
      }
    ],
    "ttl": 3600
  },
  "dependsOn": [
    "[resourceId('Microsoft.ApiManagement/service', parameters('apimName'))]",
    "[resourceId('Microsoft.Network/privateDnsZones', variables('privateDnsZoneName'))]"
  ]
}

Trying with a variable in between results in the same error - as practically the same ARM JSON is generated.尝试在两者之间使用变量会导致相同的错误 - 因为实际上生成了相同的 ARM JSON。

var privateDnsZoneName = 'azure-api.net'
resource privateDnsZone 'Microsoft.Network/privateDnsZones@2020-06-01' = {
  name: privateDnsZoneName
  location: 'Global'
}

var apimPrivateIPAddresses = apim.properties.privateIPAddresses

resource privateDnsZoneEntry 'Microsoft.Network/privateDnsZones/A@2020-06-01' = {
  name: apim.name
  parent: privateDnsZone
  properties: {
    aRecords: [for addr in apimPrivateIPAddresses: {
      ipv4Address: addr
    }]
    ttl: 3600
  }
}

I found no other way than to split private DNS zone + record creation into a Bicep module and with that getting rid of the reference() function:我发现除了将私有DNS区域 + 记录创建拆分为二头肌模块并摆脱reference() function 之外别无他法:

param privateDnsZoneName string = 'azure-api.net'
param privateDnsARecordName string
param privateDnsARecordAddresses array

resource privateDnsZone 'Microsoft.Network/privateDnsZones@2020-06-01' = {
  name: privateDnsZoneName
  location: 'Global'
}

resource privateDnsZoneEntry 'Microsoft.Network/privateDnsZones/A@2020-06-01' = {
  name: privateDnsARecordName
  parent: privateDnsZone
  properties: {
    aRecords: [for addr in privateDnsARecordAddresses: {
      ipv4Address: addr
    }]
    ttl: 3600
  }
}

and passing the privateIPAddresses array to the module.并将privateIPAddresses数组传递给模块。

module privateDnsEntry './private-dns.bicep' = {
  name: 'apim-private-dns'
  params: {
    privateDnsZoneName: 'azure-api.net'
    privateDnsARecordName: apim.name
    privateDnsARecordAddresses: apim.properties.privateIPAddresses
  }
}

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

相关问题 Azure 应用程序网关私有 ip dns 解析 - Azure Application Gateway private ip dns resolution Azure 私有 dns 第二个 ip 反向查找 - Azure private dns second ip reverse lookup 无法使用 ARM 模板创建带有 ip 的 azure 私有 dns A 记录 - Cannot create azure private dns A record with its ip by using ARM template 通过Azure REST API获取Azure VM规模集专用IP地址 - Obtaining Azure VM scale set private IP addresses through Azure REST API Bicep api 管理多个产品 - Bicep api management multiple products Azure 如何在 VNET 内部调用私有 IP 的内部 API 管理服务 - Azure How can I call internal API Management service by private IP inside VNET ARM模板输出私有端点的私有ip - ARM template output private ip of private-endpoint Azure虚拟机(ARM)| 应用程序网关| 私人IP | DNS - Azure Virtual Machines(ARM) | Application Gateway | Private ip | DNS 具有专用IP地址的Application Gateway ARM模板 - Application Gateway ARM Template with Private IP Address 通过 Python SDK 获取规模集中 VM 的私有 IP 地址(规模集中没有公共 IP 地址) - Get private IP addresses for VMs in a Scale Set via Python SDK (no public IP addresses in Scale Set)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM