azure - Terraform:Azure API 管理授权 - 客户端凭据

标签 azure terraform azure-api-management terraform-provider-azure

我想使用 Terraform 添加对 Azure API 管理的授权。我没有找到对应的Terraform资源;最接近的是 azurerm_api_management_authorization_server,但它确实支持所有属性,例如“授予类型”、“资源 URL”和“授权名称”。

resource "azurerm_api_management_authorization_server" "this" {
  count                        = length(var.apim_kv_secret_keys)
  name                         = "${var.api_management_name}-${lower(var.apim_kv_secret_keys[count.index])}"
  resource_group_name          = var.resource_group_name
  api_management_name          = var.api_management_name
  display_name                 = "${var.api_management_name}-${lower(var.apim_kv_secret_keys[count.index])}"

  grant_types = [
    "clientCredentials",
  ]
  authorization_methods = [
    "GET",
  ]
}

enter image description here

更新:6 月 26 日 我尝试了建议的解决方案并发现了以下内容

enter image description here

最佳答案

首先,要传递资源 URL,您可以使用 client_registration_endpoint 属性,因为这是执行此授权服务器的资源/客户端注册的页面的 URI。

对于 grant_type 作为 clientcredentials,您可以将其传递为

grant_types = ["clientCredentials", ] 详细信息如下。

如果您使用客户端凭据进行授权,则需要 token_endpoint不记名身份验证发送方法之一。

provider "azurerm" {
  features {}
}

data "azurerm_resource_group" "main"{
  name = "Jahnavi"
}

data "azurerm_api_management" "example" {
  name                = "newjahapim"
  resource_group_name = data.azurerm_resource_group.main.name
}

resource "azurerm_api_management_authorization_server" "example" {
  name                         = "test-server"
  api_management_name          = data.azurerm_api_management.example.name
  resource_group_name          = data.azurerm_resource_group.main.name
  display_name                 = "Test Server"
  authorization_endpoint       = "https://example.mydomain.com/client/authorize"
  token_endpoint                = "https://example.com/token"
  client_id                    = "<clientID>"
  client_registration_endpoint = "https://testserver.com/client/register"
  bearer_token_sending_methods  = ["authorizationHeader"]

  grant_types = [
    "clientCredentials",
  ]
  authorization_methods = [
    "GET",
  ]
}

Terraform 使用有效的配置进行初始化 terraform init

enter image description here

已执行 terraform计划:

enter image description here

使用最终更改进行部署 terraform apply:

enter image description here

引用terraform registry了解上述 APIM 授权服务器下使用的属性及其用途。

关于azure - Terraform:Azure API 管理授权 - 客户端凭据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76533931/

相关文章:

c# - 从azure apim中的XML响应获取属性值

Azure API 管理 - 未强制执行订阅 key

iis - 发布到 Azure VM 后对 Web 应用程序进行更改

terraform - 在 Terraform 脚本中设置 DigitalOcean 项目

python - 错误: 'no pg_hba.conf entry for host' using Django with PostgreSQL?

json - 在 Terraform 变量中使用 JSON 格式的字符串

azure - 使用私有(private) DockerHub 存储库中的 Terraform 在 Azure 上部署容器

azure-api-management - Azure API 网关策略

azure - Microsoft 托管代理 - 指定与组织不同的区域

azure - 我想更改 Microsoft Azure 虚拟机大小而不丢失数据