Skip to content

Commit

Permalink
updated api gateway openapi config
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Bakhmetev committed Sep 18, 2024
1 parent 9f729ee commit b34f58c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
17 changes: 12 additions & 5 deletions tf-aws-rest-api-gateway/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@ terraform {
}

locals {
create_log_group = var.logging_level != "OFF"
log_group_arn = local.create_log_group ? module.cloudwatch_log_group.log_group_arn : null
create_log_group = var.logging_level != "OFF"
log_group_arn = local.create_log_group ? module.cloudwatch_log_group.log_group_arn : null
stage_name = var.stage_name != "" ? var.stage_name : module.name.environment
}

data "template_file" "this" {
template = var.api_template

vars = var.api_template_vars
}

module "name" {
Expand All @@ -20,7 +27,7 @@ module "name" {

resource "aws_api_gateway_rest_api" "this" {
name = module.name.id
body = jsonencode(var.openapi_config)
body = data.template_file.this.rendered
tags = module.name.tags

endpoint_configuration {
Expand Down Expand Up @@ -51,7 +58,7 @@ resource "aws_api_gateway_deployment" "this" {
resource "aws_api_gateway_stage" "this" {
deployment_id = aws_api_gateway_deployment.this.id
rest_api_id = aws_api_gateway_rest_api.this.id
stage_name = var.stage_name != "" ? var.stage_name : module.this.stage
stage_name = local.stage_name
xray_tracing_enabled = var.xray_tracing_enabled
tags = module.name.tags

Expand All @@ -68,7 +75,7 @@ resource "aws_api_gateway_stage" "this" {
resource "aws_cloudwatch_log_group" "this" {
count = local.create_log_group ? 1 : 0

name = "${aws_api_gateway_rest_api.this.id}/${var.stage_name}"
name = "${aws_api_gateway_rest_api.this.id}/${local.stage_name}"
retention_in_days = var.cloudwatch_logs_retention_in_days
}

Expand Down
14 changes: 9 additions & 5 deletions tf-aws-rest-api-gateway/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,16 @@ variable "tags" {
description = "Additional custom tags (e.g. `{'Billing': 'Department_1'}`)."
}

# See https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-swagger-extensions.html for additional
# configuration information.
variable "openapi_config" {
description = "The OpenAPI specification for the API"
type = any
variable "api_template" {
type = string
default = null
description = "API Gateway OpenAPI 3 template file"
}

variable "api_template_vars" {
type = map(string)
default = {}
description = "Variables required in the OpenAPI template file"
}

variable "endpoint_type" {
Expand Down

0 comments on commit b34f58c

Please sign in to comment.