Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: AWS CloudWatch alarm not associating with metric for S3 bucket policy changes #35361

Open
sebasti-reeta-mary opened this issue Jan 18, 2024 · 2 comments
Labels
bug Addresses a defect in current functionality. service/cloudwatch Issues and PRs that pertain to the cloudwatch service. service/logs Issues and PRs that pertain to the logs service.

Comments

@sebasti-reeta-mary
Copy link

sebasti-reeta-mary commented Jan 18, 2024

Terraform Core Version

1.6.6

AWS Provider Version

5.32.1, 4.67.0

Affected Resource(s)

aws_cloudwatch_metric_alarm

Expected Behavior

The metric alarm should be associated with the metric for CIS-S3BucketPolicyChanges.

Actual Behavior

The deployment was all successful. However the alarm was not associated with the metric. I have implemented same code for other resource action monitoring/alerting everything works except for this one and no errors too.

Attaching screenshot of non-association of alarm with metric:
image

image

Relevant Error/Panic Output Snippet

No errors.

Terraform Configuration Files

resource "aws_cloudwatch_log_metric_filter" "s3_bucket_policy_changes" {
  count          = var.alerting_enabled ? 1 : 0
  name           = "CIS-S3BucketPolicyChanges"
  pattern        = "{ ($.eventSource = s3.amazonaws.com) && (($.eventName = PutBucketAcl) || ($.eventName = PutBucketPolicy) || ($.eventName = PutBucketCors) || ($.eventName = PutBucketLifecycle) || ($.eventName = PutBucketReplication) || ($.eventName = DeleteBucketPolicy) || ($.eventName = DeleteBucketCors) || ($.eventName = DeleteBucketLifecycle) || ($.eventName = DeleteBucketReplication)) }"
  log_group_name = var.log_group_name
  metric_transformation {
    name      = "S3BucketPolicyChanges"
    namespace = "CISAWSBenchmarks"
    value     = "1"
  }
}

resource "aws_cloudwatch_metric_alarm" "s3_bucket_policy_changes" {
  count                     = var.alerting_enabled ? 1 : 0
  alarm_name                = "CIS-S3BucketPolicyChanges"
  comparison_operator       = "GreaterThanOrEqualToThreshold"
  evaluation_periods        = "1"
  metric_name               = aws_cloudwatch_log_metric_filter.s3_bucket_policy_changes[0].id
  namespace                 = "CISAWSBenchmarks"
  period                    = "120"
  statistic                 = "Sum"
  threshold                 = "1"
  alarm_description         = "Monitoring changes to S3 bucket policies may reduce time to detect and correct permissive policies on sensitive S3 buckets."
  alarm_actions             = [aws_sns_topic.cis_alerts_sns_topic.arn]
  treat_missing_data        = "notBreaching"
  insufficient_data_actions = []
  tags                      = merge({ "Name" = "S3BucketsPolicyChangesAlarm" }, var.custom_tags)
}

Steps to Reproduce

Please provide the inputs for log_group_name (any existing log group name) and alarm_actions can be set to [].

terraform init
terraform plan
terraform apply

Debug Output

No response

Panic Output

No response

Important Factoids

No response

References

No response

Would you like to implement a fix?

None

@sebasti-reeta-mary sebasti-reeta-mary added the bug Addresses a defect in current functionality. label Jan 18, 2024
Copy link

Community Note

Voting for Prioritization

  • Please vote on this issue by adding a 👍 reaction to the original post to help the community and maintainers prioritize this request.
  • Please see our prioritization guide for information on how we prioritize.
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.

Volunteering to Work on This Issue

  • If you are interested in working on this issue, please leave a comment.
  • If this would be your first contribution, please review the contribution guide.

@github-actions github-actions bot added service/cloudwatch Issues and PRs that pertain to the cloudwatch service. service/logs Issues and PRs that pertain to the logs service. labels Jan 18, 2024
@terraform-aws-provider terraform-aws-provider bot added the needs-triage Waiting for first response or review from a maintainer. label Jan 18, 2024
@sebasti-reeta-mary
Copy link
Author

Attaching code as a file. Remove .txt at end to reproduce.
main.tf.txt

@justinretzolk justinretzolk removed the needs-triage Waiting for first response or review from a maintainer. label Jan 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Addresses a defect in current functionality. service/cloudwatch Issues and PRs that pertain to the cloudwatch service. service/logs Issues and PRs that pertain to the logs service.
Projects
None yet
Development

No branches or pull requests

2 participants