-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
196 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"terraform.languageServer": { | ||
"enabled": true | ||
}, | ||
"terraform.indexing": { | ||
"enabled": false, | ||
"liveIndexing": false, | ||
"delay": 500, | ||
"exclude": [ | ||
".terraform/**/*", | ||
"**/.terraform/**/*" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,46 @@ | ||
# tf-apigateway | ||
Terraform API Gateway Module | ||
# Terraform API Gateway Module | ||
|
||
## About: | ||
|
||
Supports basic setup of API Gateway with an OpenAPI 3 YML document: | ||
|
||
These parameters configure the use of the OpenAPI 3 document: | ||
- __api_template__: API Gateway OpenAPI 3 template file | ||
- __api_template_vars__: Variables required in the OpenAPI template file | ||
|
||
## How to use: | ||
|
||
Call the module: | ||
|
||
```terraform | ||
# ----------------------------------------------------------------------------- | ||
# API Gateway | ||
# ----------------------------------------------------------------------------- | ||
module "apigateway" { | ||
source = "github.com/rpstreef/tf-apigateway" | ||
resource_tag_name = var.resource_tag_name | ||
namespace = var.namespace | ||
region = var.region | ||
api_name = local.api_name | ||
api_throttling_rate_limit = var.api_throttling_rate_limit | ||
api_throttling_burst_limit = var.api_throttling_burst_limit | ||
api_metrics_enabled = var.api_metrics_enabled | ||
api_logging_level = var.api_logging_level | ||
api_template = file("../../services/api/${local.api_name}.yml") | ||
api_template_vars = { | ||
region = var.region | ||
cognito_user_pool_arn = module.cognito.cognito_user_pool_arn | ||
lambda_identity_arn = module.identity.lambda_arn | ||
lambda_identity_timeout = var.lambda_identity_api_timeout | ||
lambda_user_arn = module.user.lambda_arn | ||
lambda_user_timeout = var.lambda_user_api_timeout | ||
} | ||
lambda_zip_name = local.lambda_zip_name | ||
dist_file_path = local.dist_file_path | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
locals { | ||
resource_name_prefix = "${var.namespace}-${var.resource_tag_name}" | ||
api_url = "${aws_api_gateway_deployment._.invoke_url}${aws_api_gateway_stage._.stage_name}" | ||
api_name = "${local.resource_name_prefix}-${var.api_name}" | ||
} | ||
|
||
data "template_file" "_" { | ||
template = var.api_template | ||
|
||
vars = var.api_template_vars | ||
} | ||
|
||
resource "aws_api_gateway_rest_api" "_" { | ||
name = local.api_name | ||
api_key_source = "HEADER" | ||
|
||
body = data.template_file._.rendered | ||
} | ||
|
||
resource "aws_api_gateway_deployment" "_" { | ||
rest_api_id = aws_api_gateway_rest_api._.id | ||
stage_name = "" | ||
|
||
lifecycle { | ||
create_before_destroy = true | ||
} | ||
|
||
variables = { | ||
"source_code_hash" = filebase64sha256("${var.dist_file_path}/${var.lambda_zip_name}") | ||
} | ||
} | ||
|
||
resource "aws_api_gateway_stage" "_" { | ||
stage_name = var.namespace | ||
rest_api_id = aws_api_gateway_rest_api._.id | ||
deployment_id = aws_api_gateway_deployment._.id | ||
|
||
tags = { | ||
Environment = var.namespace | ||
Name = var.resource_tag_name | ||
} | ||
} | ||
|
||
resource "aws_api_gateway_method_settings" "_" { | ||
rest_api_id = aws_api_gateway_rest_api._.id | ||
stage_name = aws_api_gateway_stage._.stage_name | ||
method_path = "*/*" | ||
|
||
settings { | ||
throttling_burst_limit = var.api_throttling_burst_limit | ||
throttling_rate_limit = var.api_throttling_rate_limit | ||
metrics_enabled = var.api_metrics_enabled | ||
logging_level = var.api_logging_level | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
output "deployment_execution_arn" { | ||
value = aws_api_gateway_deployment._.execution_arn | ||
} | ||
|
||
output "rest_api_id" { | ||
value = aws_api_gateway_rest_api._.id | ||
} | ||
|
||
output "api_url" { | ||
value = local.api_url | ||
} | ||
|
||
output "api_name" { | ||
value = local.api_name | ||
} | ||
|
||
output "api_stage" { | ||
value = aws_api_gateway_stage._.stage_name | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# ----------------------------------------------------------------------------- | ||
# Variables: General | ||
# ----------------------------------------------------------------------------- | ||
|
||
variable "namespace" { | ||
description = "AWS resource namespace/prefix" | ||
} | ||
|
||
variable "region" { | ||
description = "AWS region" | ||
} | ||
|
||
variable "resource_tag_name" { | ||
description = "Resource name for billing purposes" | ||
} | ||
|
||
# ----------------------------------------------------------------------------- | ||
# Variables: API Gateway | ||
# ----------------------------------------------------------------------------- | ||
variable "api_name" { | ||
description = "API Gateway endpoint name" | ||
} | ||
|
||
variable "api_template" { | ||
description = "API Gateway OpenAPI 3 template file" | ||
} | ||
|
||
variable "api_template_vars" { | ||
description = "Variables required in the OpenAPI template file" | ||
type = map | ||
} | ||
|
||
variable "api_throttling_rate_limit" { | ||
description = "API Gateway total requests across all API's within a REST endpoint" | ||
} | ||
|
||
variable "api_throttling_burst_limit" { | ||
description = "API Gateway total concurrent connections allowed for all API's within a REST endpoint" | ||
} | ||
|
||
variable "api_metrics_enabled" { | ||
description = "Enables detailed API Gateway metrics" | ||
type = bool | ||
default = false | ||
} | ||
|
||
variable "api_logging_level" { | ||
description = " (Optional) Specifies the logging level for this method, which effects the log entries pushed to Amazon CloudWatch Logs. The available levels are OFF, ERROR, and INFO." | ||
type = string | ||
default = "OFF" | ||
} | ||
|
||
# ----------------------------------------------------------------------------- | ||
# Variables: Misc. | ||
# ----------------------------------------------------------------------------- | ||
variable "lambda_zip_name" { | ||
description = "Lambda ZIP source code filename" | ||
} | ||
|
||
variable "dist_file_path" { | ||
description = "File path to the Lambda ZIP source code" | ||
} |