我希望通过 Terraform 将架构部署到 Azure APIM。 这是基于 TF 文档 的 TF 代码和 SO 上的其他示例,例如这个问题:
resource "azurerm_api_management_api_schema" "api_schema" {
api_name = var.api.name
api_management_name = var.apim_name
resource_group_name = var.resource_group_name
schema_id = "schema01"
content_type = "application/vnd.oai.openapi.components+json"
value = file("schema.json")
}
这是schema.json文件的内容
{
"properties": {
"contentType": "application/vnd.oai.openapi.components+json",
"document": {
"components": {
"schemas": {
"Thing": {
"type": "object",
"properties": {
"id": {
"type": "string",
"nullable": true
}
},
"additionalProperties": false
},
"ThingArray": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Thing"
}
}
}
}
}
}
}
当我运行 Terraform 时,没有任何错误。但是,门户中也没有可见的定义:
如果我使用 Azure API 获取架构,我会得到以下响应 - 它的值似乎是字符串而不是纯 JSON:
{
"id": "***REDACTED***",
"type": "Microsoft.ApiManagement/service/apis/schemas",
"name": "schema01",
"properties": {
"contentType": "application/vnd.oai.openapi.components+json",
"document": {
"value": "{\r\n \"properties\": {\r\n \"contentType\": \"application\/vnd.oai.openapi.components+json\",\r\n \"document\": {\r\n \"components\": {\r\n \"schemas\": {\r\n \"Thing\": {\r\n \"type\": \"object\",\r\n \"properties\": {\r\n \"id\": {\r\n \"type\": \"string\",\r\n \"nullable\": true\r\n }\r\n },\r\n \"additionalProperties\": false\r\n },\r\n \"ThingArray\": {\r\n \"type\": \"array\",\r\n \"items\": {\r\n \"$ref\": \"#\/components\/schemas\/Thing\"\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n}"
}
}
}
如果我使用 API 通过 PUT 方法更新模式,使用相同的 schema.json 作为有效负载,值看起来正确(所有纯 JSON):
{
"id": "***REDACTED***",
"type": "Microsoft.ApiManagement/service/apis/schemas",
"name": "schema01",
"properties": {
"contentType": "application/vnd.oai.openapi.components+json",
"document": {
"components": {
"schemas": {
"Thing": {
"type": "object",
"properties": {
"id": {
"type": "string",
"nullable": true
}
},
"additionalProperties": false
},
"ThingArray": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Thing"
}
}
}
}
}
}
}
...定义出现在门户中:
谁能看出我做错了什么?
谢谢