我的 REST API 有 OpenAPI 3.0 规范 (YAML),我需要在 Terraform 模板 (HCL) 中描述与 AWS API Gateway 资源相同的 REST API。
有什么工具可以帮我自动转换吗?
最佳答案
AWS 的 API Gateway directly supports importing an OpenAPI 3.0 spec定义 API 网关的所有相关部分。
使用 Terraform 这可以通过 aws_api_gateway_rest_api
resource 来完成和 body
parameter .
tests for the resource 中给出了一个示例:
resource "aws_api_gateway_rest_api" "test" {
name = "foo"
body = <<EOF
{
"swagger": "2.0",
"info": {
"title": "foo",
"version": "2017-04-20T04:08:08Z"
},
"schemes": [
"https"
],
"paths": {
"/test": {
"get": {
"responses": {
"200": {
"description": "200 response"
}
},
"x-amazon-apigateway-integration": {
"type": "HTTP",
"uri": "https://www.google.de",
"httpMethod": "GET",
"responses": {
"default": {
"statusCode": 200
}
}
}
}
}
}
}
EOF
}
您还可以使用 file
函数直接从 YAML 文件加载 OpenAPI 规范:
resource "aws_api_gateway_rest_api" "test" {
name = "foo"
body = file("${path.module}/api.yml")
}
关于amazon-web-services - 将 OpenAPI 规范中描述的 REST API 转换为 Terraform 模板中描述的 AWS API Gateway REST API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60214612/