s3.tf 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. resource "aws_s3_bucket" "storage" {
  8. bucket = "${var.instance_name}-${var.environment}"
  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. }
  36. }
  37. resource "aws_s3_bucket_public_access_block" "awsconfig_bucket_block_public_access" {
  38. block_public_acls = true
  39. block_public_policy = true
  40. bucket = aws_s3_bucket.storage.id
  41. ignore_public_acls = true
  42. restrict_public_buckets = true
  43. }
  44. # Versioning prevents accidental deletion of records
  45. resource "aws_s3_bucket_versioning" "storage" {
  46. bucket = aws_s3_bucket.storage.id
  47. versioning_configuration {
  48. status = "Enabled"
  49. }
  50. }
  51. //AWS Provider outdated arguments <4.4.0
  52. /*resource "aws_s3_bucket" "storage" {
  53. bucket = "${var.instance_name}-${var.environment}"
  54. acl = "private"
  55. force_destroy = var.instance_termination_protection ? false : true # reverse of termination protection, destroy if no termination protection
  56. server_side_encryption_configuration {
  57. rule {
  58. apply_server_side_encryption_by_default {
  59. kms_master_key_id = aws_kms_key.s3.arn
  60. sse_algorithm = "aws:kms"
  61. }
  62. }
  63. }
  64. lifecycle_rule {
  65. id = "DeleteAfter90Days"
  66. enabled = true
  67. abort_incomplete_multipart_upload_days = 7
  68. expiration {
  69. days = 90
  70. }
  71. }
  72. }
  73. */