From 17a0eeb2435c23cfa13f1fd442076c630923d84d Mon Sep 17 00:00:00 2001 From: jiajames Date: Wed, 7 Feb 2024 11:11:59 -0500 Subject: [PATCH 1/2] Add api gateway --- modules/api_gateway/main.tf | 86 +++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 modules/api_gateway/main.tf diff --git a/modules/api_gateway/main.tf b/modules/api_gateway/main.tf new file mode 100644 index 00000000..883befab --- /dev/null +++ b/modules/api_gateway/main.tf @@ -0,0 +1,86 @@ +terraform { + cloud { + organization = "dydxprotocol" + + workspaces { + tags = ["api-gateway"] + } + } + + required_providers { + aws = { + source = "hashicorp/aws" + version = "~> 3.0" + } + } +} + +provider "aws" { + region = "ap-northeast-1" +} + +resource "aws_apigatewayv2_api" "ApiGatewayV2Api" { + name = "dydx-amplitude-proxy" + api_key_selection_expression = "$request.header.x-api-key" + protocol_type = "HTTP" + route_selection_expression = "$request.method $request.path" + + cors_configuration { + allow_credentials = false + allow_headers = [ + "*" + ] + allow_methods = [ + "*" + ] + allow_origins = [ + "*" + ] + expose_headers = [ + "*" + ] + max_age = 0 + } + + tags = {} +} + +resource "aws_apigatewayv2_stage" "ApiGatewayV2Stage" { + name = "proxy-main" + api_id = "${aws_apigatewayv2_api.ApiGatewayV2Api.id}" + tags = {} + + default_route_settings { + detailed_metrics_enabled = false + throttling_burst_limit = 5000 + throttling_rate_limit = 10000 + } + + deployment_id = aws_apigatewayv2_deployment.deployment-main.id +} + +resource "aws_apigatewayv2_route" "ApiGatewayV2Route" { + api_id = "${aws_apigatewayv2_api.ApiGatewayV2Api.id}" + api_key_required = false + authorization_type = "NONE" + route_key = "ANY /2/httpapi" + + target = "integrations/${aws_apigatewayv2_integration.ApiGatewayV2Integration.id}" +} + +resource "aws_apigatewayv2_integration" "ApiGatewayV2Integration" { + api_id = "${aws_apigatewayv2_api.ApiGatewayV2Api.id}" + connection_type = "INTERNET" + integration_method = "ANY" + integration_type = "HTTP_PROXY" + integration_uri = "https://api2.amplitude.com/2/httpapi" + timeout_milliseconds = 30000 + payload_format_version = "1.0" +} + +resource "aws_apigatewayv2_deployment" "deployment-main" { + depends_on = [aws_apigatewayv2_route.ApiGatewayV2Route] + api_id = aws_apigatewayv2_api.ApiGatewayV2Api.id + + # Other configuration... +} From e9d5f16f40ded1f479ee9065c609a2d7b044bec1 Mon Sep 17 00:00:00 2001 From: jiajames Date: Wed, 7 Feb 2024 11:15:29 -0500 Subject: [PATCH 2/2] lint --- modules/api_gateway/main.tf | 100 ++++++++++++++++++------------------ 1 file changed, 50 insertions(+), 50 deletions(-) diff --git a/modules/api_gateway/main.tf b/modules/api_gateway/main.tf index 883befab..974da623 100644 --- a/modules/api_gateway/main.tf +++ b/modules/api_gateway/main.tf @@ -8,79 +8,79 @@ terraform { } required_providers { - aws = { - source = "hashicorp/aws" - version = "~> 3.0" - } + aws = { + source = "hashicorp/aws" + version = "~> 3.0" + } } + + required_version = "~> 1.3.2" } provider "aws" { - region = "ap-northeast-1" + region = "ap-northeast-1" } resource "aws_apigatewayv2_api" "ApiGatewayV2Api" { - name = "dydx-amplitude-proxy" - api_key_selection_expression = "$request.header.x-api-key" - protocol_type = "HTTP" - route_selection_expression = "$request.method $request.path" + name = "dydx-amplitude-proxy" + api_key_selection_expression = "$request.header.x-api-key" + protocol_type = "HTTP" + route_selection_expression = "$request.method $request.path" - cors_configuration { - allow_credentials = false - allow_headers = [ - "*" - ] - allow_methods = [ - "*" - ] - allow_origins = [ - "*" - ] - expose_headers = [ - "*" - ] - max_age = 0 - } + cors_configuration { + allow_credentials = false + allow_headers = [ + "*" + ] + allow_methods = [ + "*" + ] + allow_origins = [ + "*" + ] + expose_headers = [ + "*" + ] + max_age = 0 + } - tags = {} + tags = {} } resource "aws_apigatewayv2_stage" "ApiGatewayV2Stage" { - name = "proxy-main" - api_id = "${aws_apigatewayv2_api.ApiGatewayV2Api.id}" - tags = {} + name = "proxy-main" + api_id = aws_apigatewayv2_api.ApiGatewayV2Api.id + tags = {} - default_route_settings { - detailed_metrics_enabled = false - throttling_burst_limit = 5000 - throttling_rate_limit = 10000 - } + default_route_settings { + detailed_metrics_enabled = false + throttling_burst_limit = 5000 + throttling_rate_limit = 10000 + } - deployment_id = aws_apigatewayv2_deployment.deployment-main.id + deployment_id = aws_apigatewayv2_deployment.deployment-main.id } resource "aws_apigatewayv2_route" "ApiGatewayV2Route" { - api_id = "${aws_apigatewayv2_api.ApiGatewayV2Api.id}" - api_key_required = false - authorization_type = "NONE" - route_key = "ANY /2/httpapi" - - target = "integrations/${aws_apigatewayv2_integration.ApiGatewayV2Integration.id}" + api_id = aws_apigatewayv2_api.ApiGatewayV2Api.id + api_key_required = false + authorization_type = "NONE" + route_key = "ANY /2/httpapi" + + target = "integrations/${aws_apigatewayv2_integration.ApiGatewayV2Integration.id}" } resource "aws_apigatewayv2_integration" "ApiGatewayV2Integration" { - api_id = "${aws_apigatewayv2_api.ApiGatewayV2Api.id}" - connection_type = "INTERNET" - integration_method = "ANY" - integration_type = "HTTP_PROXY" - integration_uri = "https://api2.amplitude.com/2/httpapi" - timeout_milliseconds = 30000 - payload_format_version = "1.0" + api_id = aws_apigatewayv2_api.ApiGatewayV2Api.id + connection_type = "INTERNET" + integration_method = "ANY" + integration_type = "HTTP_PROXY" + integration_uri = "https://api2.amplitude.com/2/httpapi" + timeout_milliseconds = 30000 + payload_format_version = "1.0" } resource "aws_apigatewayv2_deployment" "deployment-main" { depends_on = [aws_apigatewayv2_route.ApiGatewayV2Route] api_id = aws_apigatewayv2_api.ApiGatewayV2Api.id - - # Other configuration... }