Skip to content

Commit b34f58c

Browse files
author
Pavel Bakhmetev
committed
updated api gateway openapi config
1 parent 9f729ee commit b34f58c

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

tf-aws-rest-api-gateway/main.tf

+12-5
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,15 @@ terraform {
44
}
55

66
locals {
7-
create_log_group = var.logging_level != "OFF"
8-
log_group_arn = local.create_log_group ? module.cloudwatch_log_group.log_group_arn : null
7+
create_log_group = var.logging_level != "OFF"
8+
log_group_arn = local.create_log_group ? module.cloudwatch_log_group.log_group_arn : null
9+
stage_name = var.stage_name != "" ? var.stage_name : module.name.environment
10+
}
11+
12+
data "template_file" "this" {
13+
template = var.api_template
14+
15+
vars = var.api_template_vars
916
}
1017

1118
module "name" {
@@ -20,7 +27,7 @@ module "name" {
2027

2128
resource "aws_api_gateway_rest_api" "this" {
2229
name = module.name.id
23-
body = jsonencode(var.openapi_config)
30+
body = data.template_file.this.rendered
2431
tags = module.name.tags
2532

2633
endpoint_configuration {
@@ -51,7 +58,7 @@ resource "aws_api_gateway_deployment" "this" {
5158
resource "aws_api_gateway_stage" "this" {
5259
deployment_id = aws_api_gateway_deployment.this.id
5360
rest_api_id = aws_api_gateway_rest_api.this.id
54-
stage_name = var.stage_name != "" ? var.stage_name : module.this.stage
61+
stage_name = local.stage_name
5562
xray_tracing_enabled = var.xray_tracing_enabled
5663
tags = module.name.tags
5764

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

71-
name = "${aws_api_gateway_rest_api.this.id}/${var.stage_name}"
78+
name = "${aws_api_gateway_rest_api.this.id}/${local.stage_name}"
7279
retention_in_days = var.cloudwatch_logs_retention_in_days
7380
}
7481

tf-aws-rest-api-gateway/variables.tf

+9-5
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,16 @@ variable "tags" {
4545
description = "Additional custom tags (e.g. `{'Billing': 'Department_1'}`)."
4646
}
4747

48-
# See https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-swagger-extensions.html for additional
49-
# configuration information.
50-
variable "openapi_config" {
51-
description = "The OpenAPI specification for the API"
52-
type = any
48+
variable "api_template" {
49+
type = string
50+
default = null
51+
description = "API Gateway OpenAPI 3 template file"
52+
}
53+
54+
variable "api_template_vars" {
55+
type = map(string)
5356
default = {}
57+
description = "Variables required in the OpenAPI template file"
5458
}
5559

5660
variable "endpoint_type" {

0 commit comments

Comments
 (0)