我希望通过Terraform将架构部署到Azure APIM。以下是基于TF Documentation的TF代码和SO上的其他示例,例如question:
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"
}
}
}
}
}
}
}
...定义将显示在门户中:
有人知道我哪里做错了吗?
谢谢
1条答案
按热度按时间yjghlzjz1#
我运行了以下terraform脚本,但定义在Azure APIM资源中的Azure门户中不可见。
输出:-
我在APIM资源中没有看到任何定义,如下所示:-
此外,当我检查我的Azure APIM资源中的API架构时,它与您在API调用中获得的内容类似,请参阅以下内容:-
为了创建定义,我使用了适当的Open API架构和以下terraform代码:-
APIM定义Thing和Thing数组已成功创建,如下所示:-
输出:-