s3.tf 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # Prepares the S3 bucket for object storage
  2. # tfsec:ignore:aws-s3-enable-bucket-logging - We should log, but we don't
  3. resource "aws_s3_bucket" "state_storage" {
  4. # checkov:skip=CKV_AWS_18:checkov also things we should log.
  5. bucket_prefix = "${local.prefix}-"
  6. #logging {
  7. # target_bucket = "target-bucket"
  8. #}
  9. tags = merge(local.tags, { Prefix = local.prefix })
  10. }
  11. resource "aws_s3_bucket_versioning" "state_storage" {
  12. bucket = aws_s3_bucket.state_storage.id
  13. versioning_configuration {
  14. status = "Enabled"
  15. }
  16. }
  17. resource "aws_s3_bucket_server_side_encryption_configuration" "state_storage" {
  18. bucket = aws_s3_bucket.state_storage.bucket
  19. rule {
  20. apply_server_side_encryption_by_default {
  21. kms_master_key_id = "aws/s3" # Better to use a cmk
  22. sse_algorithm = "aws:kms"
  23. }
  24. }
  25. }
  26. resource "aws_s3_bucket_acl" "state_storage" {
  27. bucket = aws_s3_bucket.state_storage.id
  28. acl = "private"
  29. }
  30. resource "aws_s3_bucket_public_access_block" "state_storage" {
  31. bucket = aws_s3_bucket.state_storage.id
  32. block_public_acls = true
  33. block_public_policy = true
  34. ignore_public_acls = true
  35. restrict_public_buckets = true
  36. }
  37. # Clean up incomplete uploads. These files aren't big enough to benefit from IA pricing
  38. # and RRS is more expensive than standard.
  39. resource "aws_s3_bucket_lifecycle_configuration" "state_storage" {
  40. bucket = aws_s3_bucket.state_storage.id
  41. rule {
  42. id = "AbortIncomplete"
  43. status = "Enabled"
  44. abort_incomplete_multipart_upload {
  45. days_after_initiation = 7
  46. }
  47. }
  48. }