kms.tf 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # Because we use encryption for SNS and SQS, we need a customer managed CMK
  2. # with appropriate access. We'll use one key for everything.
  3. resource "aws_kms_key" "FCM-Key" {
  4. description = "FCM-Key"
  5. deletion_window_in_days = 7 #Might want to increase this for production use
  6. enable_key_rotation = true
  7. policy = <<POLICY
  8. {
  9. "Version": "2012-10-17",
  10. "Statement": [
  11. {
  12. "Sid": "Enable IAM User Permissions",
  13. "Effect": "Allow",
  14. "Principal": {
  15. "AWS": "arn:aws:iam::082012130604:root"
  16. },
  17. "Action": "kms:*",
  18. "Resource": "*"
  19. },
  20. {
  21. "Sid": "Allow Amazon Services to use this key",
  22. "Effect": "Allow",
  23. "Principal": {
  24. "Service": "sns.amazonaws.com"
  25. },
  26. "Action": [
  27. "kms:Decrypt",
  28. "kms:GenerateDataKey*"
  29. ],
  30. "Resource": "*"
  31. },
  32. {
  33. "Sid": "Allow CloudWatch Events to use this key",
  34. "Effect": "Allow",
  35. "Principal": {
  36. "Service": "events.amazonaws.com"
  37. },
  38. "Action": "kms:*",
  39. "Resource": "*"
  40. },
  41. {
  42. "Sid": "Grant access to lambda functions",
  43. "Effect": "Allow",
  44. "Principal": {
  45. "AWS": "${aws_iam_role.fcm-analysis-EbsEncryptionByDefault.arn}"
  46. },
  47. "Action": [
  48. "kms:GenerateDataKey*",
  49. "kms:Decrypt"
  50. ],
  51. "Resource": "*"
  52. }
  53. ]
  54. }
  55. POLICY
  56. tags = {
  57. Project = "FredsCloudMonitor"
  58. }
  59. }
  60. resource "aws_kms_alias" "FCM-Key" {
  61. name = "alias/fcm"
  62. target_key_id = "${aws_kms_key.FCM-Key.key_id}"
  63. }