1

在我的公司,我们的应用程序具有相同的环境:IT、ST、AT 和 PRD。我们使用 Terraform 来部署我们的 Azure 资源,目前正在尝试设置一个 API 管理解决方案,它将调用传递给一个 Function App 后端。

设置相当简单,我们声明了一系列 API,在它们的后端策略中我们声明了这一点:

<policies>
  <inbound>
    <set-backend-service id="apim-generated-policy" backend-id="function-at" />
  </inbound>
</policies>

在 IT/ST 中,我们已经能够成功地设置它。但是,当我们的 Terraform 管道在 AT 上运行时,它总是无法更新我们的 API,并出现以下错误:

Error: Error creating or updating API Operation Policy (Resource Group "rg-at" / API Management Service "api-at" / API "call" / Operation "get-call"):
apimanagement.APIOperationPolicyClient#CreateOrUpdate: Failure responding to request:
StatusCode=400 -- Original Error: autorest/azure: Service returned an error. Status=400 Code="ValidationError" Message="One or more fields contain incorrect values:" Details=[{"code":"ValidationError","message":"Error in element 'set-backend-service' on line 3, column 6: Backend with id 'function-at' could not be found.","target":"set-backend-service"}]

尝试在 Azure UI 中手动添加此行时,会发生相同的错误:

Error in element 'set-backend-service' on line 3, column 10:
Backend with id 'function-at' could not be found.

我不明白为什么这拒绝工作。该函数存在并且与 API 管理器位于同一资源组中。我最好的猜测是有人在其他环境中手动更改了未反映在 Terraform 代码中的设置。我该如何解决这个问题?我对 ST 和 AT API/函数进行了并排比较,没有发现任何明显的差异。

提前感谢您的帮助!

4

3 回答 3

1

After messing around with this issue for some days, it appears the problems is that to use a backend, this backend needs to be declared first so that the API manager views it as available. I was not able to find anywhere in the UI where these "available" backends can be viewed or edited, but I reached this conclusion based on the (very sparse) description here.

It also seems like this process is done automatically when adding an API manually through the UI. This however is not the case when trying to do it with Terraform, so it appears the correct procedure would be to first publish the backend with Powershell, and then try to add it to the API with TF.

于 2019-11-19T08:45:27.350 回答
1

我会说问题是您没有设置 base-url 属性,因此 APIM 服务无法使用 id 检测后端组件。您需要同时指定 base-url 和 backend-id 以防您想使用 id,如本文中所述。

于 2019-11-15T14:46:41.030 回答
1

我在 Terraform 部署期间遇到了同样的问题,对我来说,解决方案是添加api_management_backend并且在策略中我能够引用它。

于 2020-11-03T13:28:46.530 回答