尝试通过bicep获取Azure DNS入站端点的IP地址

yrdbyhpb  于 2023-06-24  发布在  其他
关注(0)|答案(1)|浏览(66)

我目前正在进行Azure部署,遇到了一些不便。我需要获取DNS Inboud端点的IP地址。此资源已存在。我可以这样引用资源:

param dnsInboundEndpointName string
resource dnsInboundEndpoint 'Microsoft.Network/dnsResolvers/inboundEndpoints@2022-07-01' existing = {
  name: dnsInboundEndpointName
}

我想在创建防火墙策略时使用这个(稍微简化了):

resource firewallPolicy 'Microsoft.Network/firewallPolicies@2022-09-01' = {
  name: azureFirewallPolicyName
  location: location
  properties: {
    dnsSettings: {
        enableProxy: true
        servers: [dnsInboundEndpoint.properties.ipConfigurations[0].privateIpAddress]
    }
    sku: {
      tier: azureFirewallPolicySku
    }
  }
}

现在,当我尝试部署它时,我得到了以下错误:

'The template resource 'xxx' at line '1' and column '1359' is not valid: The language expression property array index '1' is out of bounds.

我尝试创建一个这样的param:

param test string = dnsInboundEndpoint.properties.ipConfigurations[0].privateIpAddress

一个这样的var:

var dnsInboundEndpointIP = {
  ip: dnsInboundEndpoint.properties.ipConfigurations[0].privateIpAddress
}

但我一直收到这个错误。
我想知道如何引用DNS入站端点的IP地址。

falq053o

falq053o1#

您缺少dnsResolver资源的名称。InboundEndpoints是子资源,需要指定父资源:

param dnsResolverName string
param dnsInboundEndpointName string
...

// Get a reference to the dns resolver resource 
resource dnsResolver 'Microsoft.Network/dnsResolvers@2022-07-01' existing = {
  name: dnsResolverName
}

// Get a reference to the inbound rule
resource dnsInboundEndpoint 'Microsoft.Network/dnsResolvers/inboundEndpoints@2022-07-01' existing = {
  name: dnsInboundEndpointName
  parent: dnsResolver
}

// Create firewall policy
resource firewallPolicy 'Microsoft.Network/firewallPolicies@2022-09-01' = {
  ...
  properties: {
    dnsSettings: {
      enableProxy: true
      servers: [
        dnsInboundEndpoint.properties.ipConfigurations[0].privateIpAddress
      ]
    }
    ...
  }
}

相关问题