Skip to content

Commit ed4d74a

Browse files
authored
add bucket policy for writing logs (#4)
1 parent ee35788 commit ed4d74a

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

main.tf

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,35 @@
1+
data "aws_elb_service_account" "default" {}
2+
3+
#------------------------------------------------------------------------------
4+
# IAM POLICY DOCUMENT - For access logs to the s3 bucket
5+
#------------------------------------------------------------------------------
6+
data "aws_iam_policy_document" "lb_logs_access_policy_document" {
7+
statement {
8+
effect = "Allow"
9+
10+
principals {
11+
type = "AWS"
12+
identifiers = [data.aws_elb_service_account.default.arn]
13+
}
14+
15+
actions = [
16+
"s3:PutObject",
17+
]
18+
19+
resources = [
20+
"arn:aws:s3:::${var.name_prefix}-lb-logs/*",
21+
]
22+
}
23+
}
24+
25+
#------------------------------------------------------------------------------
26+
# IAM POLICY - For access logs to the s3 bucket
27+
#------------------------------------------------------------------------------
28+
resource "aws_s3_bucket_policy" "lb_logs_access_policy" {
29+
bucket = aws_s3_bucket.logs.id
30+
policy = data.aws_iam_policy_document.lb_logs_access_policy_document.json
31+
}
32+
133
#------------------------------------------------------------------------------
234
# S3 BUCKET - For access logs
335
#------------------------------------------------------------------------------

0 commit comments

Comments
 (0)