Skip to content

Commit

Permalink
add support for cloudwatch retention
Browse files Browse the repository at this point in the history
  • Loading branch information
akerl committed Apr 3, 2024
1 parent 99c7bc5 commit be98c0c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
12 changes: 12 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,22 @@ resource "aws_api_gateway_deployment" "this" {
resource "aws_cloudwatch_log_group" "this" {
name = "${var.function_name}-apigw"

retention_in_days = var.cloudwatch_retention_in_days

kms_key_id = var.kms_key_arn == "" ? null : var.kms_key_arn
}

resource "aws_cloudwatch_log_group" "stage" {
name = "API-Gateway-Execution-Logs_${aws_api_gateway_rest_api.this.id}/prod"

retention_in_days = var.cloudwatch_retention_in_days

kms_key_id = var.kms_key_arn == "" ? null : var.kms_key_arn
}

resource "aws_api_gateway_stage" "this" {
depends_on = [aws_cloudwatch_log_group.stage]

deployment_id = aws_api_gateway_deployment.this.id
rest_api_id = aws_api_gateway_rest_api.this.id
stage_name = "prod"
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,9 @@ variable "kms_key_arn" {
type = string
default = ""
}

variable "cloudwatch_retention_in_days" {
description = "Days to retain cloudwatch logs"
type = number
default = 0
}

0 comments on commit be98c0c

Please sign in to comment.