diff --git a/tf-aws-rest-api-gateway/main.tf b/tf-aws-rest-api-gateway/main.tf index b3dbebe..ded5d8d 100644 --- a/tf-aws-rest-api-gateway/main.tf +++ b/tf-aws-rest-api-gateway/main.tf @@ -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" { @@ -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 { @@ -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 @@ -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 } diff --git a/tf-aws-rest-api-gateway/variables.tf b/tf-aws-rest-api-gateway/variables.tf index c0411cf..a5cee9b 100644 --- a/tf-aws-rest-api-gateway/variables.tf +++ b/tf-aws-rest-api-gateway/variables.tf @@ -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" {