s3.smartstore.tf 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # This is the smartstore bucket. This is the data. Keep this safe.
  2. resource "aws_s3_bucket" "splunk-smartstore" {
  3. bucket = "ftd-splunk-smartstore"
  4. versioning {
  5. enabled = true # Allows us to archive frozen data directly into glacier without splunk intervention
  6. }
  7. lifecycle {
  8. # Set to TRUE for production!
  9. prevent_destroy = false
  10. }
  11. # set to FALSE for production!
  12. force_destroy = true
  13. server_side_encryption_configuration {
  14. rule {
  15. apply_server_side_encryption_by_default {
  16. kms_master_key_id = "${aws_kms_key.splunk_s3_key.arn}"
  17. sse_algorithm = "aws:kms"
  18. }
  19. }
  20. }
  21. # This will save some money by moving to "infrequently accessed" after a period of time
  22. lifecycle_rule {
  23. id = "InfrequentAccessAfteraYear"
  24. enabled = true
  25. transition {
  26. # For production, probably set this to something longer, like 90 days or a year
  27. days = 30
  28. storage_class = "STANDARD_IA"
  29. }
  30. noncurrent_version_transition {
  31. days = 0
  32. storage_class = "GLACIER"
  33. }
  34. # This would be a good place to transition to deep archive a few days/weeks/months after
  35. # the transition to glacier, if you're really only rarely going to access it.
  36. }
  37. tags = {
  38. Project = "Splunk"
  39. Environment = "Production"
  40. }
  41. }
  42. resource "aws_s3_bucket_public_access_block" "keep_smartstore_safe" {
  43. bucket = "${aws_s3_bucket.splunk-smartstore.id}"
  44. block_public_acls = true
  45. block_public_policy = true
  46. ignore_public_acls = true
  47. restrict_public_buckets = true
  48. }
  49. data "template_file" "s3_splunk_bucket_policy" {
  50. template = "${file("policies/s3_splunk_bucket_policy.json.tpl")}"
  51. vars = {
  52. account = "${data.aws_caller_identity.current.account_id}"
  53. bucket_arn = "${aws_s3_bucket.splunk-smartstore.arn}"
  54. vpc_cidr = "${data.terraform_remote_state.network.outputs.vpc_cidr}"
  55. role_arn = "${aws_iam_role.Splunk-EC2-Standalone.arn}"
  56. }
  57. }
  58. resource "aws_s3_bucket_policy" "splunk_servers_only" {
  59. bucket = "${aws_s3_bucket.splunk-smartstore.id}"
  60. policy = "${data.template_file.s3_splunk_bucket_policy.rendered}"
  61. }