Skip to content

Commit a4c65c0

Browse files
committed
retooled for existing log group
1 parent 6613659 commit a4c65c0

File tree

3 files changed

+33
-79
lines changed

3 files changed

+33
-79
lines changed

terraform/csoc_sentinel.tf

Lines changed: 0 additions & 78 deletions
This file was deleted.

terraform/modules/api_gateway/api.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ resource "aws_apigatewayv2_stage" "default" {
2121
}
2222
access_log_settings {
2323
destination_arn = aws_cloudwatch_log_group.api_access_log.arn
24-
format = "{ \"requestId\":\"$context.requestId\", \"extendedRequestId\":\"$context.extendedRequestId\", \"ip\": \"$context.identity.sourceIp\", \"caller\":\"$context.identity.caller\", \"user\":\"$context.identity.user\", \"requestTime\":\"$context.requestTime\", \"httpMethod\":\"$context.httpMethod\", \"resourcePath\":\"$context.resourcePath\", \"status\":\"$context.status\", \"protocol\":\"$context.protocol\", \"responseLength\":\"$context.responseLength\", \"authorizerError\":\"$context.authorizer.error\", \"authorizerStatus\":\"$context.authorizer.status\", \"requestIsValid\":\"$context.authorizer.is_valid\"\"environment\":\"$context.authorizer.environment\" }"
24+
format = "{ \"requestId\":\"$context.requestId\", \"extendedRequestId\":\"$context.extendedRequestId\", \"ip\":\"$context.identity.sourceIp\", \"caller\":\"$context.identity.caller\", \"user\":\"$context.identity.user\", \"requestTime\":\"$context.requestTime\", \"httpMethod\":\"$context.httpMethod\", \"resourcePath\":\"$context.resourcePath\", \"status\":\"$context.status\", \"protocol\":\"$context.protocol\", \"responseLength\":\"$context.responseLength\", \"accountId\":\"$context.accountId\", \"apiId\":\"$context.apiId\", \"stage\":\"$context.stage\", \"api_key\":\"$context.identity.apiKey\", \"authorizerError\":\"$context.authorizer.error\", \"authorizerStatus\":\"$context.authorizer.status\", \"requestIsValid\":\"$context.authorizer.is_valid\", \"environment\":\"$context.authorizer.environment\" }"
2525
}
2626

2727
# Bug in terraform-aws-provider with perpetual diff

terraform/modules/api_gateway/logs.tf

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,35 @@ resource "aws_iam_role_policy" "cloudwatch" {
5353
}
5454
EOF
5555
}
56+
57+
resource "aws_iam_role_policy_attachment" "cwlogs_apigateway_policy" {
58+
role = aws_iam_role.api_cloudwatch.name
59+
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonAPIGatewayPushToCloudWatchLogs"
60+
}
61+
62+
# TODO un-hardcode the region
63+
# e.g.
64+
# "logs.${data.aws_region.current.region}.amazonaws.com"
65+
66+
resource "aws_iam_role" "cwlogs_subscription_role" {
67+
name = "${local.short_prefix}-cwlogs-subscription-role"
68+
assume_role_policy = jsonencode({
69+
Version = "2012-10-17",
70+
Statement = [{
71+
Effect = "Allow",
72+
Sid = "",
73+
Principal = {
74+
Service = "logs.eu-west-2.amazonaws.com"
75+
},
76+
Action = "sts:AssumeRole"
77+
}]
78+
})
79+
}
80+
81+
resource "aws_cloudwatch_log_subscription_filter" "cwlogs_subscription_logfilter" {
82+
name = "${local.short_prefix}-cwlogs-subscription-logfilter"
83+
log_group_name = aws_cloudwatch_log_group.api_access_log.name
84+
filter_pattern = ""
85+
destination_arn = "arn:aws:logs:eu-west-2:693466633220:destination:api_gateway_log_destination"
86+
role_arn = aws_iam_role.cwlogs_subscription_role.arn
87+
}

0 commit comments

Comments
 (0)