Skip to content

Commit ce033e2

Browse files
[PRMP-1553] - Implement CloudWatch RUM PoC (UI Analytics) (#258)
* Fix Type * test will deploy with module's separated from cloudwatch logs * changes count for cloud watch rum * FIxed typo missing _ * FIxed typo trailing / * moved couldwatch rum to root * Fixed formatting * fixed resource name and removed identity pool from rum * Added roles for cognito * Update Rum policies * fmt fix * Update role and policies * Amended AssumeRole type * more changes to roles * Another refactor of policies and roles for rum * Replaced Service with Principal for role * another attempt to fix some of the role errors * reformatting * removed prohibited line * all users for test * generated policy * commented out potential unused policy attachment * refactor of policies and roles * disabled cs_log_enabled * Added Authorization for app rum monitoring * reformatted cloudwatch * Updated roles and polices to match required permissions and resources, using web identity * Removed un needed additional region on string equals * Renaming some Terraform objects * Everything is optional * Made changes requested in the pull request, removed potentially un-needed policies and roles * Commented out ServiceRole tag * Removed un-needed code commented on last commit --------- Co-authored-by: Kris Bloe <[email protected]>
1 parent f127786 commit ce033e2

File tree

2 files changed

+83
-1
lines changed

2 files changed

+83
-1
lines changed

infrastructure/cloudwatch_rum.tf

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
locals {
2+
cognito_role_name = "${terraform.workspace}-cognito-unauth-role"
3+
}
4+
5+
resource "aws_iam_role" "cognito_unauthenticated" {
6+
count = local.is_production ? 0 : 1
7+
name = local.cognito_role_name
8+
9+
assume_role_policy = jsonencode({
10+
Version = "2012-10-17",
11+
Statement = [
12+
{
13+
Effect = "Allow",
14+
Principal : {
15+
Federated : "cognito-identity.amazonaws.com"
16+
},
17+
Action = "sts:AssumeRoleWithWebIdentity",
18+
Condition = {
19+
StringEquals = {
20+
"cognito-identity.amazonaws.com:aud" = aws_cognito_identity_pool.cloudwatch_rum[0].id
21+
},
22+
"ForAnyValue:StringLike" = {
23+
"cognito-identity.amazonaws.com:amr" = "unauthenticated"
24+
}
25+
}
26+
}
27+
]
28+
})
29+
}
30+
31+
resource "aws_iam_policy" "cloudwatch_rum_cognito_access" {
32+
count = local.is_production ? 0 : 1
33+
name = "${terraform.workspace}-cloudwatch-rum-cognito-access-policy"
34+
description = "Policy for unauthenticated Cognito identities"
35+
36+
policy = jsonencode(
37+
{
38+
"Version" : "2012-10-17",
39+
"Statement" : [
40+
{
41+
"Effect" : "Allow",
42+
"Action" : "rum:PutRumEvents",
43+
"Resource" : "arn:aws:rum:${local.current_region}:${local.current_account_id}:appmonitor/${aws_rum_app_monitor.ndr[0].id}"
44+
}
45+
]
46+
})
47+
}
48+
49+
resource "aws_iam_role_policy_attachment" "cloudwatch_rum_cognito_unauth" {
50+
count = local.is_production ? 0 : 1
51+
role = aws_iam_role.cognito_unauthenticated[0].name
52+
policy_arn = aws_iam_policy.cloudwatch_rum_cognito_access[0].arn
53+
}
54+
55+
resource "aws_cognito_identity_pool_roles_attachment" "cloudwatch_rum" {
56+
count = local.is_production ? 0 : 1
57+
identity_pool_id = aws_cognito_identity_pool.cloudwatch_rum[0].id
58+
59+
roles = {
60+
unauthenticated = aws_iam_role.cognito_unauthenticated[0].arn
61+
}
62+
}
63+
64+
resource "aws_cognito_identity_pool" "cloudwatch_rum" {
65+
count = local.is_production ? 0 : 1
66+
identity_pool_name = "${terraform.workspace}-cloudwatch-rum-identity-pool"
67+
allow_unauthenticated_identities = true
68+
}
69+
70+
resource "aws_rum_app_monitor" "ndr" {
71+
count = local.is_production ? 0 : 1
72+
name = "${terraform.workspace}-app-monitor"
73+
domain = "*.${var.domain}"
74+
cw_log_enabled = false
75+
76+
app_monitor_configuration {
77+
identity_pool_id = aws_cognito_identity_pool.cloudwatch_rum[0].id
78+
allow_cookies = true
79+
enable_xray = false
80+
session_sample_rate = 1.0
81+
telemetries = ["errors", "performance", "http"]
82+
}
83+
}

infrastructure/modules/cloudwatch/main.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ resource "aws_cloudwatch_log_group" "ndr_cloudwatch_log_group" {
1313
resource "aws_cloudwatch_log_stream" "log_stream" {
1414
name = "${terraform.workspace}_${var.cloudwatch_log_stream_name}_log_Stream"
1515
log_group_name = "aws_cloudwatch_log_group.ndr_cloudwatch_log_group"
16-
1716
tags = {
1817
Name = "${terraform.workspace}_${var.cloudwatch_log_stream_name}_log_stream"
1918
Owner = var.owner

0 commit comments

Comments
 (0)