|
| 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