Terraform : 如何连接 azurerm_api_management_authorization_server 到 azurerm_api_management_api

Terraform : How to hookup azurerm_api_management_authorization_server to azurerm_api_management_api

您好,感谢您花时间看我的问题。

我正在使用 terraform 在 Azure 中创建一个 api_management 对象。我已经掌握了 API 的产品、政策、订阅和用户的设置。

我的开发人员在 Azure 中的 API 管理对象上设置了一个授权服务器,我使用 azurerm_api_management_authorization_server 对其进行了自动化,效果很好。

但是,我看不到如何在 terraform 中配置 API 设置以使用该授权服务器。 API User Authorisation Settings

看起来好像此功能目前无法通过 Terraform 获得,这可以通过针对 azurerm 提供商的公开问题找到: https://github.com/terraform-providers/terraform-provider-azurerm/issues/3341

为了让您继续在 Terraform 中构建基础架构,我建议您使用 azurerm_template_deployment 资源。

这样您就可以利用 ARM 部署中可用的 ARM API: https://docs.microsoft.com/en-us/azure/templates/microsoft.apimanagement/2019-01-01/service/apis

遗憾的是,在该问题关闭之前,azurerm 提供商不会提供该功能。

Lachie White 提供的答案注释

由于我 运行 这是来自 azure devops 中的 yaml 管道,我通过使用 azure powershell 任务绕过了这个限制

- task: AzurePowerShell@5
        inputs:
          azureSubscription: 'Subscription (111111111-1111-1111-1111-111111111111)'
          ScriptType: 'InlineScript'
          Inline: |
            $ApiMgmtContext = New-AzApiManagementContext -ResourceGroupName "api-mgmt-rg" -ServiceName "api-mgmt"
            $ApiAuthorizationServer = Get-AzApiManagementAuthorizationServer -Context $ApiMgmtContext
            $ApiAuthorizationServerName = $ApiAuthorizationServer.Name
            Set-AzApiManagementApi -Context $ApiMgmtContext -ApiId "api-name" -AuthorizationServerId "$ApiAuthorizationServerName"
         azurePowerShellVersion: 'LatestVersion'