Azure API management and App Function backend: Backend with id 'foo' could not be found

倖福魔咒の 提交于 2020-05-31 03:45:07

问题


In my company we have identical environments for our application: IT, ST, AT and PRD. We use Terraform to deploy our Azure resources, and are currently attempting to set up an API management solution which passes calls to a Function App backend.

The set up is fairly simple, we have a series of APIs declared, and in their backend policies we declare this bit:

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

In IT/ST we have been able to set this successfully. However, when our Terraform pipeline runs on AT, it always fails to update our APIs with this error:

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"}]

When attempting to add this line manually in the Azure UI, the same error occurs:

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

I cannot understand why this refuses to work. The function exists and is in the same resource group as the API manager. My best guess is that someone has changed a setting manually in the other environments that is not reflected in the Terraform code. How can I go about troubleshooting this issue? I did a side-by-side comparison of the ST and AT APIs/functions and did not find any obvious differences.

Thanks in advance for any help!


回答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.




回答2:


I would say the problem is you are not setting the base-url property, so then the APIM service is not able to detect the backend component using the id. You need to specify both base-url and backend-id in case you want to use the id, as it explains in this article.



来源:https://stackoverflow.com/questions/58879254/azure-api-management-and-app-function-backend-backend-with-id-foo-could-not-b

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!