hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.84k stars 9.19k forks source link

Feature request: Cloudwatch Contributor Insights for Cloudwatch logs #17877

Open aaleksandrov opened 3 years ago

aaleksandrov commented 3 years ago

Community Note

Description

CloudWatch Contributor Insights was made Generally Available in April 2020:

Amazon CloudWatch Contributor Insights analyzes log data and creates time-series visualizations to provide a view of top contributors influencing system performance. You do this by creating Contributor Insights rules to evaluate CloudWatch Logs (including logs from AWS services) and any custom logs sent by your service or on-premises servers.

New or Affected Resource(s)

Potential Terraform Configuration

resource "aws_cloudwatch_logs_contributor_insights_rule" "abc" {
  name           = "TerraformTestRule"
  syntax =  <<RULE
{
    "Schema": {
        "Name": "CloudWatchLogRule",
        "Version": 1
    },
    "AggregateOn": "Count",
    "Contribution": {
        "Filters": [
            {
                "In": [
                    "some-keyword"
                ],
                "Match": "$.message"
            },
            {
                "In": [
                    "order"
                ],
                "Match": "$.event_type"
            }
        ],
        "Keys": [
            "$.country"
        ]
    },
    "LogFormat": "JSON",
    "LogGroupNames": [
        "/aws/lambda/api-prod"
    ]
}
RULE
}

References

ewbankkit commented 3 years ago

Related:

robh007 commented 1 year ago

I think this needs two resources, plus an additional datasource to lookup managed rules.

resource "aws_cloudwatch_contributor_insights_rule" "abc" {
  rule_name           = "TerraformTestRule"
  rule_state            = enabled
  rule_definition     =  <<RULE
{
    "Schema": {
        "Name": "CloudWatchLogRule",
        "Version": 1
    },
    "AggregateOn": "Count",
    "Contribution": {
        "Filters": [
            {
                "In": [
                    "some-keyword"
                ],
                "Match": "$.message"
            },
            {
                "In": [
                    "order"
                ],
                "Match": "$.event_type"
            }
        ],
        "Keys": [
            "$.country"
        ]
    },
    "LogFormat": "JSON",
    "LogGroupNames": [
        "/aws/lambda/api-prod"
    ]
}
RULE
}

& Also

resource "aws_cloudwatch_contributor_managed_insight_rules" "abc" {
  managed_rules = ["list of managed rules"]
  enabled = true / false
}

Also maybe a data resource to lookup managed rules.

data "aws_cloudwatch_contributor_managed_insight_rules" "abc" {
  resource_arn = "service:arn"
}