config_aggregator.tf 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. resource "aws_config_configuration_aggregator" "account" {
  2. name = "xdr-aggregator-${var.environment}"
  3. account_aggregation_source {
  4. account_ids = var.responsible_accounts[var.environment]
  5. all_regions = true
  6. }
  7. }
  8. resource "aws_sns_topic" "account-alerts" {
  9. name = "account-alerts"
  10. #kms_master_key_id = "alias/aws/sns" # TODO
  11. }
  12. resource "aws_sns_topic_policy" "account-alerts" {
  13. arn = aws_sns_topic.account-alerts.arn
  14. policy = data.aws_iam_policy_document.config-sns.json
  15. }
  16. data "aws_iam_policy_document" "config-sns" {
  17. statement {
  18. sid = "AllowConfig"
  19. actions = [ "SNS:Publish" ]
  20. effect = "Allow"
  21. resources = [ aws_sns_topic.account-alerts.arn ]
  22. principals {
  23. type = "AWS"
  24. identifiers = [ for a in var.responsible_accounts[var.environment]: "arn:${var.aws_partition}:iam::${a}:root" ]
  25. }
  26. }
  27. # This is for a service-linked role, but from https://docs.aws.amazon.com/config/latest/developerguide/sns-topic-policy.html:
  28. # "AWS Config does not recommend using a service-linked role when using Amazon SNS topic from other accounts."
  29. # statement {
  30. # sid = "AllowConfigServer"
  31. # effect = "Allow",
  32. # principals {
  33. # type = "AWS"
  34. # resources = [ ]
  35. # }
  36. # actions = [ "SNS:Publish", ]
  37. # resources = [ aws_sns_topic.account-alerts.arn ]
  38. # }
  39. }