s3.tf 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. Configuration of S3 bucket for backups
  3. Uses server side encryption to secure
  4. data.
  5. */
  6. // S3 bucket for cluster storage
  7. # tfsec:ignore:aws-s3-enable-bucket-logging TODO: enable everywhere at a later date if required
  8. resource "aws_s3_bucket" "storage" {
  9. # checkov:skip=CKV_AWS_18: see tfsec S3 logging above
  10. # checkov:skip=CKV_AWS_144: Cross-region replication TODO
  11. bucket = "xdr-${var.environment}-vmray-backups"
  12. force_destroy = var.instance_termination_protection ? false : true # reverse of termination protection, destroy if no termination protection
  13. }
  14. resource "aws_s3_bucket_acl" "s3_acl_storage" {
  15. bucket = aws_s3_bucket.storage.id
  16. acl = "private"
  17. }
  18. resource "aws_s3_bucket_server_side_encryption_configuration" "s3_sse_storage" {
  19. bucket = aws_s3_bucket.storage.id
  20. rule {
  21. apply_server_side_encryption_by_default {
  22. kms_master_key_id = aws_kms_key.s3.arn
  23. sse_algorithm = "aws:kms"
  24. }
  25. }
  26. }
  27. resource "aws_s3_bucket_lifecycle_configuration" "s3_lifecyle_storage" {
  28. bucket = aws_s3_bucket.storage.id
  29. rule {
  30. id = "DeleteAfter90Days"
  31. status = "Enabled"
  32. abort_incomplete_multipart_upload {
  33. days_after_initiation = 7
  34. }
  35. expiration {
  36. days = 90
  37. }
  38. noncurrent_version_expiration {
  39. noncurrent_days = 93 # If they've expired and not been synced back, be able to rescue them
  40. }
  41. noncurrent_version_transition {
  42. noncurrent_days = 30
  43. storage_class = "STANDARD_IA"
  44. }
  45. }
  46. }
  47. resource "aws_s3_bucket_public_access_block" "awsconfig_bucket_block_public_access" {
  48. block_public_acls = true
  49. block_public_policy = true
  50. bucket = aws_s3_bucket.storage.id
  51. ignore_public_acls = true
  52. restrict_public_buckets = true
  53. }
  54. resource "aws_s3_bucket_versioning" "versioning" {
  55. bucket = aws_s3_bucket.storage.id
  56. versioning_configuration {
  57. status = "Enabled"
  58. }
  59. }