Server access logging should be enabled on S3 Buckets so that all changes are logged and trackable. Without the logging block in your Terraform configuration, such as shown below, access and modification events to the S3 bucket will not be recorded, making it difficult to detect unauthorized access or investigate security incidents.
resource"aws_s3_bucket""positive4"{bucket="my-tf-test-bucket-unlogged"}resource"aws_iam_role""unrelated"{name="unrelated-role"assume_role_policy= jsonencode({Version="2012-10-17"Statement=[{Action="sts:AssumeRole"Effect="Allow"Principal={Service="s3.amazonaws.com"}}]})}# Targets a bucket name derived from an unrelated, unresolved resource
# attribute - not aws_s3_bucket.positive4, which remains genuinely
# unlogged. The single-bucket-in-document heuristic previously assumed
# this must target positive4 since it's the only bucket in the document -
# it doesn't; the reference here has nothing to do with positive4 at all.
resource"aws_s3_bucket_logging""external_target"{bucket=aws_iam_role.unrelated.unique_idtarget_bucket="logs"target_prefix=""}
1
2
rulesets:- Terraform / AWS # Rules to enforce / AWS.
Request a personalized demo
Get Started with Datadog
Ask AI
AI-generated responses may be inaccurate. Verify important info.