Я создаю API в AWS API Gateway. Вся инфраструктура в AWS управляется с помощью terraform. Чтобы продолжить то же самое, хотелось бы добавить конфигурацию API в terraform. У меня есть определение ресурса API в swagger, созданное инструментом зависимостей swagger, добавленным в приложение.
Мне нужно интегрировать его с terraform, но когда я пытаюсь подать заявку, мне приходится импортировать каждый ресурс из AWS, созданного swagger несколько раз. Только конфигурация шлюза API должна быть в виде terraform, а определение ресурса должно исходить от чванства. Есть ли способ добиться этого? Кроме того, мне нужно автоматизировать процесс для сотен API, пожалуйста, предложите, как это можно сделать.
Пожалуйста, поделитесь любыми соответствующими ссылками на github
Вот то, что я пробовал до сих пор,
resource "aws_api_gateway_rest_api" "api" {
name = "Hello-API"
description = "Proxy to handle requests to our API"
body = "${file("api_swagger_example.json")}"
}
//Resource created by swagger
data "aws_api_gateway_resource" "helloApp" {
rest_api_id = "${aws_api_gateway_rest_api.api.id}"
path = "/api/v1/hello"
}
//Need to import from first, since it was created using swagger
resource "aws_api_gateway_method" "helloApp-POST" {
rest_api_id = "${aws_api_gateway_rest_api.api.id}"
resource_id = "${data.aws_api_gateway_resource.helloApp.id}"
http_method = "POST"
authorization = "NONE"
}
//Importing first
resource "aws_api_gateway_method_response" "response_200" {
rest_api_id = "${aws_api_gateway_rest_api.api.id}"
resource_id = "${data.aws_api_gateway_resource.helloApp.id}"
http_method = "${aws_api_gateway_method.helloApp-POST.http_method}"
status_code = "200"
response_parameters = "${var.method_response_parameters}"
}
//Importing first
resource "aws_api_gateway_method_response" "response_401" {
rest_api_id = "${aws_api_gateway_rest_api.api.id}"
resource_id = "${data.aws_api_gateway_resource.helloApp.id}"
http_method = "${aws_api_gateway_method.helloApp-POST.http_method}"
status_code = "401"
response_parameters = "${var.method_response_parameters}"
}
resource "aws_api_gateway_integration_response" "helloApp-ok" {
rest_api_id = "${aws_api_gateway_rest_api.api.id}"
resource_id = "${data.aws_api_gateway_resource.helloApp.id}"
http_method = "${aws_api_gateway_method.helloApp-POST.http_method}"
status_code = "${aws_api_gateway_method_response.response_200.status_code}"
response_parameters = "${var.integration_response_parameters}"
}
resource "aws_api_gateway_integration_response" "helloApp-401" {
rest_api_id = "${aws_api_gateway_rest_api.api.id}"
resource_id = "${data.aws_api_gateway_resource.helloApp.id}"
http_method = "${aws_api_gateway_method.helloApp-POST.http_method}"
status_code = "${aws_api_gateway_method_response.response_401.status_code}"
selection_pattern = "4\\d{2}"
response_parameters = "${var.integration_response_parameters}"
}
//Importing first
resource "aws_api_gateway_method_response" "helloApp_response_200" {
rest_api_id = "${aws_api_gateway_rest_api.api.id}"
resource_id = "${data.aws_api_gateway_resource.helloApp.id}"
http_method = "${aws_api_gateway_method.helloApp-POST.http_method}"
status_code = "200"
response_parameters = "${var.method_response_parameters}"
}
//Importing first
resource "aws_api_gateway_method_response" "helloApp_response_401" {
rest_api_id = "${aws_api_gateway_rest_api.api.id}"
resource_id = "${data.aws_api_gateway_resource.helloApp.id}"
http_method = "${aws_api_gateway_method.helloApp-POST.http_method}"
status_code = "401"
response_parameters = "${var.method_response_parameters}"
}
resource "aws_api_gateway_integration" "helloAppIntegration" {
rest_api_id = "${aws_api_gateway_rest_api.api.id}"
resource_id = "${data.aws_api_gateway_resource.helloApp.id}"
http_method = "${aws_api_gateway_method.helloApp-POST.http_method}"
type = "HTTP"
integration_http_method = "POST"
connection_type = "VPC_LINK"
connection_id = "${data.aws_api_gateway_vpc_link.hello_vpc_link.id}"
uri = "${var.hello-endpoint-url}"
request_templates = {
"application/json" = <<REQUEST_TEMPLATE
$input.json('$')
REQUEST_TEMPLATE
}
}
resource "aws_api_gateway_integration_response" "helloApp-ok" {
rest_api_id = "${aws_api_gateway_rest_api.api.id}"
resource_id = "${data.aws_api_gateway_resource.helloApp.id}"
http_method = "${aws_api_gateway_method.helloApp-POST.http_method}"
status_code = "${aws_api_gateway_method_response.helloApp_response_200.status_code}"
response_parameters = "${var.integration_response_parameters}"
}
resource "aws_api_gateway_integration_response" "helloApp-401" {
rest_api_id = "${aws_api_gateway_rest_api.api.id}"
resource_id = "${data.aws_api_gateway_resource.helloApp.id}"
http_method = "${aws_api_gateway_method.helloApp-POST.http_method}"
status_code = "${aws_api_gateway_method_response.helloApp_response_401.status_code}"
selection_pattern = "4\\d{2}"
response_parameters = "${var.integration_response_parameters}"
}
resource "aws_api_gateway_deployment" "deploy-dev" {
depends_on = [
"aws_api_gateway_integration.helloAppIntegration",
"aws_api_gateway_method.helloApp-POST"
]
rest_api_id = "${aws_api_gateway_rest_api.api.id}"
stage_name = "dev"
}
resource "aws_api_gateway_stage" "dev" {
stage_name = "dev"
rest_api_id = "${aws_api_gateway_rest_api.api.id}"
deployment_id = "${aws_api_gateway_deployment.deploy-dev.id}"
}
resource "aws_api_gateway_usage_plan" "dev-usage-plan" {
name = "hello-usage-plan"
description = "hello API Basic Usage Plan"
api_stages {
api_id = "${aws_api_gateway_rest_api.api.id}"
stage = "${aws_api_gateway_deployment.deploy-dev.stage_name}"
}
throttle_settings {
burst_limit = 5
rate_limit = 10
}
}
resource "aws_api_gateway_method_settings" "helloApp-POST" {
rest_api_id = "${aws_api_gateway_rest_api.api.id}"
stage_name = "${aws_api_gateway_stage.dev.stage_name}"
method_path = "${data.aws_api_gateway_resource.helloApp.path_part}/${aws_api_gateway_method.helloApp-POST.http_method}"
settings {
metrics_enabled = true
logging_level = "INFO"
}
}
Это было так неприятно и практически невозможно было импортировать каждый ресурс для всех API и обновлений. Есть ли лучший способ интеграции?