You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Bicep输出API Management Service的TXT记录值?

在Bicep中输出APIM自定义域名的TXT验证记录值

为APIM配置自定义域名并使用托管证书时,Azure会生成域名所有权验证所需的TXT记录值。你可以通过Bicep输出直接获取该值,无需从报错信息中提取。

实现代码

1. 完整APIM资源定义

resource apiManagementService 'Microsoft.ApiManagement/service@2022-08-01' = {
  name: 'your-apim-resource-name'
  location: 'eastus' // 替换为你的部署区域
  sku: {
    name: 'Developer'
    capacity: 1
  }
  properties: {
    publisherEmail: 'admin@example.com'
    publisherName: 'Your Company'
    hostnameConfigurations: [
      {
        certificateSource: 'Managed'
        defaultSslBinding: true
        hostName: 'api.yourdomain.com' // 替换为你的自定义域名
        negotiateClientCertificate: false
        type: 'Proxy'
      }
    ]
  }
}

2. 添加输出语句

针对指定的自定义域名,提取对应的TXT记录值:

// 输出目标域名的TXT验证记录
output domainVerificationTxt string = (
  filter(apiManagementService.properties.hostnameConfigurations, cfg => cfg.hostName == 'api.yourdomain.com')[0]
).customHostnameConfiguration.txtRecord

如果仅配置了一个自定义域名,可简化为:

output domainVerificationTxt string = apiManagementService.properties.hostnameConfigurations[0].customHostnameConfiguration.txtRecord

注意事项

  • 该TXT记录仅在首次部署自定义域名且使用托管证书时生成,域名验证完成后值不会变更。
  • 部署完成后,输出值会直接显示在部署结果中,可直接用于DNS配置。

内容的提问来源于stack exchange,提问作者Sheleby

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 07:16:14