简体   繁体   English

Terraform - Azure - Azure API terraform 管理中的每个 api 操作我在哪里指定后端 API?

[英]Terraform - Azure - Where do I specify the backend API for each api operation in Azure API Management through terraform?

I am trying to create API Management Service using terraform. I am able to map most of the components from the UI to the documentation.我正在尝试使用 terraform 创建 API 管理服务。我能够 map 从 UI 到文档的大部分组件。 But, I cannot see any resource block or configuration option in但是,我看不到任何资源块或配置选项

azurerm_api_management_api_operation

to add a backend URL for an operation.为操作添加后端 URL。 How do I add it through terraform?如何通过terraform添加?

Azure portal overview Azure门户概览

Azure portal setup Azure 门户设置

I saw this resource block in the documentation for the backend我在后端文档中看到了这个资源块

resource "azurerm_api_management_backend" "example" {
  name                = "example-backend"
  resource_group_name = azurerm_resource_group.example.name
  api_management_name = azurerm_api_management.example.name
  protocol            = "http"
  url                 = "https://backend"
}

But there is no way to link it to an operation in an API但是没有办法将它链接到 API 中的操作

This might work...这可能工作...

Set the operation policy using https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/api_management_api_operation_policy使用https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/api_management_api_operation_policy设置操作策略

eg例如

resource "azurerm_api_management_api_operation_policy" "policy" {
  resource_group_name = data.azurerm_api_management.this.resource_group_name
  api_management_name = data.azurerm_api_management.this.name
  api_name            = azurerm_api_management_api.this.name
  operation_id        = var.operationId
  xml_content         = var.operationPolicy
  depends_on = [
    azurerm_api_management_api.this
  ]
}

then in the policy xml set the back end url using the set-backend-service policy.然后在策略 xml 中使用 set-backend-service 策略设置后端 url。 eg例如

<policies>
    <inbound>
        <base />
        <set-backend-service base-url="https://back-end-url" />
    </inbound>
    <backend>
        <base />
    </backend>
    <outbound>
        <base />
    </outbound>
    <on-error>
        <base />
    </on-error>
</policies>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM