Skip to content

Commit

Permalink
added gateway permission to write logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Bakhmetev committed Sep 18, 2024
1 parent eb605ca commit f8d49f9
Showing 1 changed file with 44 additions and 7 deletions.
51 changes: 44 additions & 7 deletions tf-aws-rest-api-gateway/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,6 @@ 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}/${local.stage_name}"
retention_in_days = var.cloudwatch_logs_retention_in_days
}

resource "aws_api_gateway_method_settings" "all" {
rest_api_id = aws_api_gateway_rest_api.this.id
stage_name = aws_api_gateway_stage.this.stage_name
Expand All @@ -89,3 +82,47 @@ resource "aws_api_gateway_method_settings" "all" {
data_trace_enabled = var.data_trace_enabled
}
}

resource "aws_cloudwatch_log_group" "this" {
count = local.create_log_group ? 1 : 0

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

resource "aws_iam_role" "this" {
name = "${module.name.id}-api-gateway"

assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = "sts:AssumeRole"
Effect = "Allow"
Principal = {
Service = "apigateway.amazonaws.com"
}
},
]
})
}

resource "aws_iam_role_policy" "this" {
name = "${module.name.id}-api-gateway"
role = aws_iam_role.this.id

policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
]
Effect = "Allow"
Resource = "*"
},
]
})
}

0 comments on commit f8d49f9

Please sign in to comment.