Skip to content

Commit 27b9404

Browse files
committed
[NRL-1158] Allow AWS Backup to write to backup-reports bucket
1 parent 0dbda49 commit 27b9404

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

terraform/account-wide-infrastructure/dev/aws-backup.tf

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11

2-
# First, we create an S3 bucket for compliance reports.
32
resource "aws_s3_bucket" "backup_reports" {
43
bucket_prefix = "${local.prefix}-backup-reports"
54
}
@@ -45,6 +44,22 @@ resource "aws_s3_bucket_policy" "backup_reports_bucket_policy" {
4544
}
4645
}
4746
},
47+
{
48+
Sid = "AllowBackupReportsWrite"
49+
Effect = "Allow"
50+
Principal = {
51+
AWS = "arn:aws:iam::${local.account_id}:role/aws-service-role/reports.backup.amazonaws.com/AWSServiceRoleForBackupReports"
52+
}
53+
Action = "s3:PutObject"
54+
Resource = [
55+
"${aws_s3_bucket.backup_reports.arn}/*",
56+
]
57+
Condition = {
58+
StringEquals = {
59+
"s3:x-amz-acl" = "bucket-owner-full-control"
60+
}
61+
}
62+
}
4863
]
4964
})
5065
}

terraform/account-wide-infrastructure/dev/data.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
data "aws_region" "current" {}
22

3+
data "aws_caller_identity" "current" {}
4+
35
data "aws_secretsmanager_secret_version" "identities_account_id" {
46
secret_id = aws_secretsmanager_secret.identities_account_id.name
57
}

terraform/account-wide-infrastructure/dev/locals.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ locals {
33
project = "nhsd-nrlf"
44
environment = terraform.workspace
55
prefix = "${local.project}--${local.environment}"
6+
account_id = data.aws_caller_identity.current.account_id
67

78
notification_emails = tolist(jsondecode(data.aws_secretsmanager_secret_version.emails.secret_string))
89
}

0 commit comments

Comments
 (0)