iam_moose_sh_instance_profile.tf 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. module "moose_instance_profile" {
  2. count = local.is_moose ? 1 : 0
  3. source = "../../../submodules/iam/base_instance_profile"
  4. prefix = "moose-splunk-sh"
  5. aws_partition = var.aws_partition
  6. aws_account_id = var.aws_account_id
  7. }
  8. data "aws_iam_policy_document" "moose_splunk_sh_policy_doc" {
  9. count = local.is_moose ? 1 : 0
  10. # Moose splunk SH can assumerole into the C2 and mdr-prod-root-ca accounts to run the ACM audit report
  11. statement {
  12. sid = "AllowAssumeRole"
  13. effect = "Allow"
  14. actions = [
  15. "sts:AssumeRole"
  16. ]
  17. resources = [
  18. "arn:${var.aws_partition}:iam::*:role/service/run_audit_report_role",
  19. "arn:${ var.aws_partition }:iam::${ var.aws_account_id }:role/service/splunk_apps_s3"
  20. ]
  21. }
  22. # Moose splunk SH can grab the ACM audit reports
  23. statement {
  24. sid = ""
  25. effect = "Allow"
  26. resources = ["arn:${var.aws_partition}:s3:::xdr-ca-audit-reports"]
  27. actions = [
  28. "s3:ListBucket",
  29. "s3:ListBucketVersions",
  30. ]
  31. }
  32. statement {
  33. sid = ""
  34. effect = "Allow"
  35. resources = ["arn:${var.aws_partition}:s3:::xdr-ca-audit-reports/*"]
  36. actions = [
  37. "s3:GetObject",
  38. "s3:GetObjectVersion",
  39. ]
  40. }
  41. }
  42. resource "aws_iam_policy" "moose_splunk_sh_policy" {
  43. count = local.is_moose ? 1 : 0
  44. name = "moose_splunk_sh"
  45. path = "/"
  46. policy = data.aws_iam_policy_document.moose_splunk_sh_policy_doc[count.index].json
  47. }
  48. resource "aws_iam_role_policy_attachment" "moose_splunk_sh_attach" {
  49. count = local.is_moose ? 1 : 0
  50. role = module.moose_instance_profile[count.index].role_id
  51. policy_arn = aws_iam_policy.moose_splunk_sh_policy[count.index].arn
  52. }
  53. #This policy needs to be create prior to creating the Salt Master
  54. resource "aws_iam_role_policy_attachment" "moose_splunk_sh_policy_attach_binaries" {
  55. count = local.is_moose ? 1 : 0
  56. role = module.moose_instance_profile[count.index].role_id
  57. policy_arn = "arn:${var.aws_partition}:iam::${var.aws_account_id}:policy/launchroles/default_instance_s3_binaries"
  58. }