s3.tf 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. resource "aws_s3_bucket" "storage" {
  8. bucket = "xdr-${var.environment}-vmray-backups"
  9. force_destroy = var.instance_termination_protection ? false : true # reverse of termination protection, destroy if no termination protection
  10. }
  11. resource "aws_s3_bucket_acl" "s3_acl_storage" {
  12. bucket = aws_s3_bucket.storage.id
  13. acl = "private"
  14. }
  15. resource "aws_s3_bucket_server_side_encryption_configuration" "s3_sse_storage" {
  16. bucket = aws_s3_bucket.storage.id
  17. rule {
  18. apply_server_side_encryption_by_default {
  19. kms_master_key_id = aws_kms_key.s3.arn
  20. sse_algorithm = "aws:kms"
  21. }
  22. }
  23. }
  24. resource "aws_s3_bucket_lifecycle_configuration" "s3_lifecyle_storage" {
  25. bucket = aws_s3_bucket.storage.id
  26. rule {
  27. id = "DeleteAfter90Days"
  28. status = "Enabled"
  29. abort_incomplete_multipart_upload {
  30. days_after_initiation = 7
  31. }
  32. expiration {
  33. days = 90
  34. }
  35. noncurrent_version_expiration {
  36. noncurrent_days = 93 # If they've expired and not been synced back, be able to rescue them
  37. }
  38. noncurrent_version_transition {
  39. noncurrent_days = 30
  40. storage_class = "STANDARD_IA"
  41. }
  42. }
  43. }
  44. resource "aws_s3_bucket_public_access_block" "awsconfig_bucket_block_public_access" {
  45. block_public_acls = true
  46. block_public_policy = true
  47. bucket = aws_s3_bucket.storage.id
  48. ignore_public_acls = true
  49. restrict_public_buckets = true
  50. }
  51. resource "aws_s3_bucket_versioning" "versioning" {
  52. bucket = aws_s3_bucket.storage.id
  53. versioning_configuration {
  54. status = "Enabled"
  55. }
  56. }