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

Azure APIM:如何通过Bicep将现有API关联至新建产品?

将现有API关联到APIM产品的Bicep实现

要把已添加到APIM的现有API关联到你的产品,你需要创建产品-API关联资源,对应Bicep资源类型Microsoft.ApiManagement/service/products/apis@2020-12-01,这和GUI里点击「添加API到产品」的操作完全等价。

完整代码示例

假设你已经有一个现有API,先通过existing关键字引用它,再创建关联资源:

// 引用你的APIM实例
resource apiManagement 'Microsoft.ApiManagement/service@2020-12-01' existing = {
  name: 'your-apim-service-name'
}

// 你的产品定义(原代码)
resource myapi_product 'Microsoft.ApiManagement/service/products@2020-12-01' = {
  parent: apiManagement
  name: 'the-name-of-the-product'
  properties: {
    displayName: 'displayname'
    description: 'description'
    subscriptionRequired: true
    approvalRequired: false
    state: 'published'
  }
}

// 引用APIM中已存在的目标API
resource existingApi 'Microsoft.ApiManagement/service/apis@2020-12-01' existing = {
  parent: apiManagement
  name: 'your-existing-api-name' // 替换为你的现有API名称
}

// 建立产品与API的关联
resource productApiLink 'Microsoft.ApiManagement/service/products/apis@2020-12-01' = {
  parent: myapi_product
  name: existingApi.name
  properties: {} // 该资源无需额外配置属性
}

关键说明

  • 关联资源的父资源必须是你定义的产品myapi_product
  • 关联资源的名称必须和目标API的名称完全一致
  • 如果目标API是在同一个Bicep模板中创建的,无需使用existing关键字,直接引用其资源名即可

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.24 01:17:06