s3.tf 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. Configuration of S3 bucket for certs and replay
  3. storage. Uses server side encryption to secure
  4. session replays and SSL certificates.
  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 = "${var.instance_name}-${var.environment}"
  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. }
  39. }
  40. resource "aws_s3_bucket_public_access_block" "awsconfig_bucket_block_public_access" {
  41. block_public_acls = true
  42. block_public_policy = true
  43. bucket = aws_s3_bucket.storage.id
  44. ignore_public_acls = true
  45. restrict_public_buckets = true
  46. }
  47. # Versioning prevents accidental deletion of records
  48. resource "aws_s3_bucket_versioning" "storage" {
  49. bucket = aws_s3_bucket.storage.id
  50. versioning_configuration {
  51. status = "Enabled"
  52. }
  53. }
  54. //AWS Provider outdated arguments <4.4.0
  55. /*resource "aws_s3_bucket" "storage" {
  56. bucket = "${var.instance_name}-${var.environment}"
  57. acl = "private"
  58. force_destroy = var.instance_termination_protection ? false : true # reverse of termination protection, destroy if no termination protection
  59. server_side_encryption_configuration {
  60. rule {
  61. apply_server_side_encryption_by_default {
  62. kms_master_key_id = aws_kms_key.s3.arn
  63. sse_algorithm = "aws:kms"
  64. }
  65. }
  66. }
  67. lifecycle_rule {
  68. id = "DeleteAfter90Days"
  69. enabled = true
  70. abort_incomplete_multipart_upload_days = 7
  71. expiration {
  72. days = 90
  73. }
  74. }
  75. }
  76. */