Skip to content

Instantly share code, notes, and snippets.

@jorgeancal
Last active October 12, 2023 13:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jorgeancal/36ca9f03bf35864a35eb7863e3868d3a to your computer and use it in GitHub Desktop.
Save jorgeancal/36ca9f03bf35864a35eb7863e3868d3a to your computer and use it in GitHub Desktop.
Create a Centralised AWS Monitoring Account.
data "aws_organizations_organization" "current" {}
data "aws_region" "this" {}
resource "aws_oam_sink" "monitoring_account_oam_sink" {
name = "AWSoamSinkObservabilityMonitoring"
}
resource "aws_oam_sink_policy" "monitoring_account_oam_sink_policy" {
sink_identifier = aws_oam_sink.monitoring_account_oam_sink.id
policy = data.aws_iam_policy_document.monitoring_account_oam_sink_policy.json
}
data "aws_iam_policy_document" "monitoring_account_oam_sink_policy" {
statement {
actions = ["oam:CreateLink", "oam:UpdateLink"]
resources = ["*"]
effect = "Allow"
principals {
identifiers = ["*"]
type = "*"
}
condition {
test = "ForAllValues:StringEquals"
values = ["AWS::Logs::LogGroup", "AWS::CloudWatch::Metric", "AWS::XRay::Trace"]
variable = "oam:ResourceTypes"
}
condition {
test = "ForAnyValue:StringEquals"
values = [data.aws_organizations_organization.current.id]
variable = "aws:PrincipalOrgID"
}
}
}
output "oam" {
value = aws_oam_sink.monitoring_account_oam_sink.arn
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment