Skip to content

Commit fd42cf2

Browse files
CCM-8197: Cross Account Observability
1 parent f8068f1 commit fd42cf2

File tree

5 files changed

+77
-0
lines changed

5 files changed

+77
-0
lines changed

infrastructure/terraform/components/acct/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
| <a name="input_kms_deletion_window"></a> [kms\_deletion\_window](#input\_kms\_deletion\_window) | When a kms key is deleted, how long should it wait in the pending deletion state? | `string` | `"30"` | no |
2222
| <a name="input_letter_suppliers"></a> [letter\_suppliers](#input\_letter\_suppliers) | Letter suppliers enabled in the account (across all environments) | <pre>map(object({<br/> enable_polling = bool<br/> default_supplier = optional(bool)<br/> }))</pre> | `{}` | no |
2323
| <a name="input_log_retention_in_days"></a> [log\_retention\_in\_days](#input\_log\_retention\_in\_days) | The retention period in days for the Cloudwatch Logs events to be retained, default of 0 is indefinite | `number` | `0` | no |
24+
| <a name="input_oam_sink_id"></a> [oam\_sink\_id](#input\_oam\_sink\_id) | The ID of the Cloudwatch OAM sink in the appropriate observability account. | `string` | `""` | no |
2425
| <a name="input_observability_account_id"></a> [observability\_account\_id](#input\_observability\_account\_id) | The Observability Account ID that needs access | `string` | n/a | yes |
2526
| <a name="input_project"></a> [project](#input\_project) | The name of the tfscaffold project | `string` | n/a | yes |
2627
| <a name="input_region"></a> [region](#input\_region) | The AWS Region | `string` | n/a | yes |

infrastructure/terraform/components/acct/iam_policy_github_deploy_overload.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ data "aws_iam_policy_document" "github_deploy" {
2323
"cloudformation:*",
2424
"cognito-idp:*",
2525
"firehose:*",
26+
"logs:*",
27+
"oam:*",
2628
"pipes:*",
2729
"ses:*",
2830
"sns:*",
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
resource "aws_oam_link" "cross_account_obs" {
2+
count = var.oam_sink_id != "" ? 1 : 0
3+
label_template = "$AccountName"
4+
resource_types = [
5+
"AWS::CloudWatch::Metric",
6+
"AWS::Logs::LogGroup"
7+
]
8+
sink_identifier = "arn:aws:oam:eu-west-2:${var.observability_account_id}:sink/${var.oam_sink_id}"
9+
tags = var.default_tags
10+
}
11+
12+
data "aws_iam_policy" "cloudwatch_read_only" {
13+
count = var.oam_sink_id != "" ? 1 : 0
14+
name = "CloudWatchReadOnlyAccess"
15+
}
16+
17+
data "aws_iam_policy" "cloudwatch_automatic_dashboards" {
18+
count = var.oam_sink_id != "" ? 1 : 0
19+
name = "CloudWatchAutomaticDashboardsAccess"
20+
}
21+
22+
data "aws_iam_policy" "aws_xray_read_only" {
23+
count = var.oam_sink_id != "" ? 1 : 0
24+
name = "AWSXrayReadOnlyAccess"
25+
}
26+
27+
data "aws_iam_policy_document" "cross_account_obs_assume_role_policy" {
28+
count = var.oam_sink_id != "" ? 1 : 0
29+
statement {
30+
effect = "Allow"
31+
principals {
32+
type = "AWS"
33+
identifiers = [var.observability_account_id]
34+
}
35+
actions = ["sts:AssumeRole"]
36+
}
37+
}
38+
39+
resource "aws_iam_role" "cross_account_obs_role" {
40+
count = var.oam_sink_id != "" ? 1 : 0
41+
name = "CloudWatch-CrossAccountSharingRole"
42+
assume_role_policy = data.aws_iam_policy_document.cross_account_obs_assume_role_policy[0].json
43+
}
44+
45+
resource "aws_iam_role_policy_attachment" "cloudwatch_read_only_attachment" {
46+
count = var.oam_sink_id != "" ? 1 : 0
47+
policy_arn = data.aws_iam_policy.cloudwatch_read_only[0].arn
48+
role = aws_iam_role.cross_account_obs_role[0].name
49+
}
50+
51+
resource "aws_iam_role_policy_attachment" "cloudwatch_automatic_dashboards_attachment" {
52+
count = var.oam_sink_id != "" ? 1 : 0
53+
policy_arn = data.aws_iam_policy.cloudwatch_automatic_dashboards[0].arn
54+
role = aws_iam_role.cross_account_obs_role[0].name
55+
}
56+
57+
resource "aws_iam_role_policy_attachment" "aws_xray_read_only_attachment" {
58+
count = var.oam_sink_id != "" ? 1 : 0
59+
policy_arn = data.aws_iam_policy.aws_xray_read_only[0].arn
60+
role = aws_iam_role.cross_account_obs_role[0].name
61+
}

infrastructure/terraform/components/acct/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,9 @@ variable "letter_suppliers" {
114114

115115
default = {}
116116
}
117+
118+
variable "oam_sink_id" {
119+
description = "The ID of the Cloudwatch OAM sink in the appropriate observability account."
120+
type = string
121+
default = ""
122+
}

infrastructure/terraform/components/app/cloudwatch_log_group_amplify.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,10 @@ 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" {
7+
name = "${local.csi}-amplify"
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-acct-firehose-logs"
11+
}

0 commit comments

Comments
 (0)