|
| 1 | +resource "aws_oam_link" "cross_account_obs" { |
| 2 | + label_template = "$AccountName" |
| 3 | + resource_types = var.resource_types |
| 4 | + sink_identifier = "arn:aws:oam:${var.region}:${var.observability_account_id}:sink/${var.oam_sink_id}" |
| 5 | + tags = var.default_tags |
| 6 | + |
| 7 | + link_configuration { |
| 8 | + dynamic "log_group_configuration" { |
| 9 | + for_each = var.log_group_configuration != null ? [var.log_group_configuration] : [] |
| 10 | + content { |
| 11 | + filter = log_group_configuration.value.filter |
| 12 | + } |
| 13 | + } |
| 14 | + |
| 15 | + dynamic "metric_configuration" { |
| 16 | + for_each = var.metric_configuration != null ? [var.metric_configuration] : [] |
| 17 | + content { |
| 18 | + filter = metric_configuration.value.filter |
| 19 | + } |
| 20 | + } |
| 21 | + } |
| 22 | +} |
| 23 | + |
| 24 | +data "aws_iam_policy" "cloudwatch_read_only" { |
| 25 | + name = "CloudWatchReadOnlyAccess" |
| 26 | +} |
| 27 | + |
| 28 | +data "aws_iam_policy" "cloudwatch_automatic_dashboards" { |
| 29 | + name = "CloudWatchAutomaticDashboardsAccess" |
| 30 | +} |
| 31 | + |
| 32 | +data "aws_iam_policy" "aws_xray_read_only" { |
| 33 | + name = "AWSXrayReadOnlyAccess" |
| 34 | +} |
| 35 | + |
| 36 | +data "aws_iam_policy_document" "cross_account_obs_assume_role_policy" { |
| 37 | + statement { |
| 38 | + effect = "Allow" |
| 39 | + principals { |
| 40 | + type = "AWS" |
| 41 | + identifiers = [var.observability_account_id] |
| 42 | + } |
| 43 | + actions = ["sts:AssumeRole"] |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +resource "aws_iam_role" "cross_account_obs_role" { |
| 48 | + name = "CloudWatch-CrossAccountSharingRole" |
| 49 | + assume_role_policy = data.aws_iam_policy_document.cross_account_obs_assume_role_policy.json |
| 50 | +} |
| 51 | + |
| 52 | +resource "aws_iam_role_policy_attachment" "cloudwatch_read_only_attachment" { |
| 53 | + policy_arn = data.aws_iam_policy.cloudwatch_read_only.arn |
| 54 | + role = aws_iam_role.cross_account_obs_role.name |
| 55 | +} |
| 56 | + |
| 57 | +resource "aws_iam_role_policy_attachment" "cloudwatch_automatic_dashboards_attachment" { |
| 58 | + policy_arn = data.aws_iam_policy.cloudwatch_automatic_dashboards.arn |
| 59 | + role = aws_iam_role.cross_account_obs_role.name |
| 60 | +} |
| 61 | + |
| 62 | +resource "aws_iam_role_policy_attachment" "aws_xray_read_only_attachment" { |
| 63 | + policy_arn = data.aws_iam_policy.aws_xray_read_only.arn |
| 64 | + role = aws_iam_role.cross_account_obs_role.name |
| 65 | +} |
0 commit comments