Azure Terraform API管理Graphql支持

mum43rcc  于 2023-05-29  发布在  其他
关注(0)|答案(2)|浏览(141)

我正在使用GraphQL在Azure APIM上创建API。这仍然是预览,所以直到现在我只能在门户中单击或使用Azure API Rest通过PUT请求创建它们。
我正在尝试将所有这些迁移到Terraform,但我没有找到任何网站提供有关是否有任何方法可以使用Terraform或甚至使用模块创建GraphQL API的信息。
我想做的事情是这样的:

resource "azurerm_resource_group" "example" {
  name     = "example-resources"
  location = "West Europe"
}

resource "azurerm_api_management" "example" {
  name                = "example-apim"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name
  publisher_name      = "My Company"
  publisher_email     = "company@terraform.io"

  sku_name = "Developer_1"
}

resource "azurerm_api_management_api" "example" {
  name                = "example-api"
  resource_group_name = azurerm_resource_group.example.name
  api_management_name = azurerm_api_management.example.name
  revision            = "1"
  display_name        = "Example API"
  path                = "example"
  protocols           = ["https"]

  import {
    content_format = "graphql-file"
    content_value  = "schema.graphql"
  }
}

我是Terraform的新手,我有点迷路,因为我在官方页面或任何地方都找不到任何关于这个的文档。
编辑:我试图找到的是用Terraform自动化这个过程:GraphQL Import
谢谢。

niknxzdl

niknxzdl1#

  • 下面是使用terraform的GraphQL API资源的插件提供程序。

此提供程序有几个配置输入。在大多数情况下,仅使用urlheaders

provider "graphql" {
  url = "https://your-graphql-server-url"
  headers = {
    "header1" = "header1-value"
    "header2" = "header2-value"
    ...
  }
}
  • 以下是GraphQl API与terraform的参数参考文档。
  • 下面是使用terraform创建GraphQL API的完整document
zf9nrax1

zf9nrax12#

可以通过利用terraform中的api_type属性来实现直通GraphQL API。

resource "azurerm_api_management_api" "this" {
  name                = "example-api"
  resource_group_name = azurerm_resource_group.example.name
  api_management_name = azurerm_api_management.example.name
  revision            = "1"
  display_name        = "Example API"
  path                = "example"
  protocols           = ["https"]
  api_type            = "graphql"
  service_url         = "https://swapi-graphql.azure-api.net/graphql" 
}
  • service_url-创建Azure通常从中获取架构的Web服务URL。

相关问题