Skip to content

Commit 7043323

Browse files
committed
CCM-10057: backup to S3 - tf
1 parent a12153e commit 7043323

File tree

2 files changed

+106
-0
lines changed

2 files changed

+106
-0
lines changed

infrastructure/terraform/components/acct/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
| <a name="module_obs_datasource"></a> [obs\_datasource](#module\_obs\_datasource) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/obs-datasource | v2.0.3 |
3838
| <a name="module_s3bucket_access_logs"></a> [s3bucket\_access\_logs](#module\_s3bucket\_access\_logs) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/s3bucket | v1.0.9 |
3939
| <a name="module_s3bucket_backup_reports"></a> [s3bucket\_backup\_reports](#module\_s3bucket\_backup\_reports) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/s3bucket | v1.0.8 |
40+
| <a name="module_s3bucket_data_migration_backups"></a> [s3bucket\_data\_migration\_backups](#module\_s3bucket\_data\_migration\_backups) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/s3bucket | v1.0.8 |
4041
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | 5.19.0 |
4142
## Outputs
4243

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
module "s3bucket_data_migration_backups" {
2+
source = "git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/s3bucket?ref=v1.0.8"
3+
4+
name = "data-migration-backups"
5+
6+
aws_account_id = var.aws_account_id
7+
region = var.region
8+
project = var.project
9+
environment = var.environment
10+
component = var.component
11+
12+
acl = "private"
13+
force_destroy = false
14+
versioning = true
15+
16+
lifecycle_rules = [
17+
{
18+
enabled = true
19+
20+
expiration = {
21+
days = 90
22+
}
23+
24+
noncurrent_version_expiration = {
25+
noncurrent_days = 14
26+
}
27+
}
28+
]
29+
30+
policy_documents = [
31+
data.aws_iam_policy_document.s3bucket_data_migration_backups.json
32+
]
33+
34+
bucket_logging_target = {
35+
bucket = module.s3bucket_access_logs.id
36+
}
37+
38+
public_access = {
39+
block_public_acls = true
40+
block_public_policy = true
41+
ignore_public_acls = true
42+
restrict_public_buckets = true
43+
}
44+
45+
46+
default_tags = {
47+
Name = "Data migration backups"
48+
}
49+
}
50+
51+
data "aws_iam_policy_document" "s3bucket_data_migration_backups" {
52+
statement {
53+
sid = "DontAllowNonSecureConnection"
54+
effect = "Deny"
55+
56+
actions = [
57+
"s3:*",
58+
]
59+
60+
resources = [
61+
module.s3bucket_data_migration_backups.arn,
62+
"${module.s3bucket_data_migration_backups.arn}/*",
63+
]
64+
65+
principals {
66+
type = "AWS"
67+
68+
identifiers = [
69+
"*",
70+
]
71+
}
72+
73+
condition {
74+
test = "Bool"
75+
variable = "aws:SecureTransport"
76+
77+
values = [
78+
"false",
79+
]
80+
}
81+
}
82+
83+
statement {
84+
sid = "AllowManagedAccountFullAccess"
85+
effect = "Allow"
86+
87+
actions = [
88+
"s3:ListBucket",
89+
"s3:GetObject",
90+
"s3:PutObject"
91+
]
92+
93+
resources = [
94+
"${module.s3bucket_data_migration_backups.arn}",
95+
"${module.s3bucket_data_migration_backups.arn}/*",
96+
]
97+
98+
principals {
99+
type = "AWS"
100+
identifiers = [
101+
"arn:aws:iam::${var.aws_account_id}:root"
102+
]
103+
}
104+
}
105+
}

0 commit comments

Comments
 (0)