|
| 1 | +resource "aws_cloudwatch_event_rule" "aws_backup_errors" { |
| 2 | + name = "${local.csi}-aws-backup-errors" |
| 3 | + description = "Forwards AWS Backup state changes to Custom Event Bus in Observability Account" |
| 4 | + |
| 5 | + event_pattern = jsonencode({ |
| 6 | + source = ["aws.backup"], |
| 7 | + "detail-type" = ["Backup Job State Change", "Restore Job State Change", "Copy Job State Change"], |
| 8 | + detail = { |
| 9 | + state = ["FAILED", "ABORTED"] |
| 10 | + } |
| 11 | + }) |
| 12 | +} |
| 13 | + |
| 14 | +resource "aws_cloudwatch_event_target" "aws_backup_errors" { |
| 15 | + rule = aws_cloudwatch_event_rule.aws_backup_errors.name |
| 16 | + arn = local.event_bus_arn |
| 17 | + role_arn = aws_iam_role.aws_backup_errors.arn |
| 18 | +} |
| 19 | + |
| 20 | +resource "aws_iam_role" "aws_backup_errors" { |
| 21 | + name = "${local.csi}-aws-backup-errors" |
| 22 | + |
| 23 | + assume_role_policy = jsonencode({ |
| 24 | + Version = "2012-10-17", |
| 25 | + Statement = [{ |
| 26 | + Effect = "Allow", |
| 27 | + Principal = { |
| 28 | + Service = "events.amazonaws.com" |
| 29 | + }, |
| 30 | + Action = "sts:AssumeRole" |
| 31 | + }] |
| 32 | + }) |
| 33 | +} |
| 34 | + |
| 35 | +resource "aws_iam_policy" "aws_backup_errors" { |
| 36 | + name = "${local.csi}-aws-backup-errors" |
| 37 | + |
| 38 | + policy = jsonencode({ |
| 39 | + Version = "2012-10-17", |
| 40 | + Statement = [{ |
| 41 | + Effect = "Allow", |
| 42 | + Action = "events:PutEvents", |
| 43 | + Resource = local.event_bus_arn |
| 44 | + }] |
| 45 | + }) |
| 46 | +} |
| 47 | + |
| 48 | +resource "aws_iam_role_policy_attachment" "aws_backup_errors" { |
| 49 | + role = aws_iam_role.aws_backup_errors.name |
| 50 | + policy_arn = aws_iam_policy.aws_backup_errors.arn |
| 51 | +} |
0 commit comments