For AI agents: A markdown version of this page is available at https://docs.datadoghq.com/security/code_security/iac_security/iac_rules/terraform-aws-cloudtrail-not-integrated-with-cloudwatch.md.
A documentation index is available at /llms.txt.
Integrating AWS CloudTrail with CloudWatch Logs is essential for real-time monitoring and alerting on account activity. If the cloud_watch_logs_group_arn and cloud_watch_logs_role_arn attributes are not set in the aws_cloudtrail resource, as in the following insecure configuration, CloudTrail events will only be stored in S3 with no efficient mechanism for real-time detection or automated response to suspicious activities:
resource "aws_cloudtrail" "example" {
name = "tf-trail-foobar"
s3_bucket_name = aws_s3_bucket.foo.id
// cloud_watch_logs_group_arn and cloud_watch_logs_role_arn not set
}
Without CloudWatch integration, critical security or operational issues could go unnoticed, increasing the risk of unauthorized behavior persisting undetected in your AWS environment.
A secure Terraform configuration should explicitly connect CloudTrail to CloudWatch Logs. For example: