Skip to content

Commit 1b11034

Browse files
CCM-8197: Firehose Splunk Delivery
1 parent 9fe2b31 commit 1b11034

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
resource "aws_cloudwatch_metric_stream" "metrics_to_obs_firehose" {
2+
name = "metrics-to-obs-firehose"
3+
role_arn = aws_iam_role.metrics_to_obs_firehose_role.arn
4+
firehose_arn = "arn:aws:firehose:${var.region}:${var.observability_account_id}:deliverystream/nhs-notify-main-obs-splunk-metrics-firehose"
5+
output_format = "json"
6+
}
7+
8+
resource "aws_iam_role" "metrics_to_obs_firehose_role" {
9+
name = "metric-stream-to-firehose-role"
10+
assume_role_policy = data.aws_iam_policy_document.metric_stream_assume_role_policy.json
11+
}
12+
13+
data "aws_iam_policy_document" "metric_stream_assume_role_policy" {
14+
statement {
15+
effect = "Allow"
16+
17+
principals {
18+
type = "Service"
19+
identifiers = ["streams.metrics.cloudwatch.amazonaws.com"]
20+
}
21+
22+
actions = ["sts:AssumeRole"]
23+
}
24+
}
25+
26+
resource "aws_iam_policy" "metrics_to_obs_firehose_policy" {
27+
name = "metric-stream-to-firehose-policy"
28+
description = "Policy to allow CloudWatch Metric Stream to send data to Firehose"
29+
30+
policy = data.aws_iam_policy_document.metric_stream_firehose_policy.json
31+
}
32+
33+
data "aws_iam_policy_document" "metric_stream_firehose_policy" {
34+
statement {
35+
effect = "Allow"
36+
37+
actions = [
38+
"firehose:PutRecord",
39+
"firehose:PutRecordBatch"
40+
]
41+
42+
resources = [
43+
"arn:aws:firehose:${var.region}:${var.observability_account_id}:deliverystream/nhs-notify-main-obs-splunk-metrics-firehose"
44+
]
45+
}
46+
}
47+
48+
resource "aws_iam_role_policy_attachment" "metric_stream_to_firehose_attachment" {
49+
role = aws_iam_role.metrics_to_obs_firehose_role.name
50+
policy_arn = aws_iam_policy.metrics_to_obs_firehose_policy.arn
51+
}

infrastructure/terraform/components/app/cloudwatch_log_group_amplify.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,11 @@ resource "aws_cloudwatch_log_group" "amplify" {
22
name = "/aws/amplify/${aws_amplify_app.main.id}"
33
retention_in_days = var.log_retention_in_days
44
}
5+
6+
resource "aws_cloudwatch_log_subscription_filter" "amplify_logs_to_firehose" {
7+
name = "${local.csi}-amplify-logs-to-firehose"
8+
log_group_name = aws_cloudwatch_log_group.amplify.name
9+
filter_pattern = ""
10+
destination_arn = "arn:aws:logs:${var.region}:${var.observability_account_id}:destination:nhs-notify-main-obs-firehose-logs"
11+
role_arn = aws_iam_role.amplify_logs_to_firehose_role.arn
12+
}

0 commit comments

Comments
 (0)