-
Notifications
You must be signed in to change notification settings - Fork 0
/
s3.tf
49 lines (38 loc) · 1.19 KB
/
s3.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
resource "aws_s3_bucket" "logs_bucket" {
count = var.create_logs_bucket == true ? 1 : 0
bucket = "${var.module_prefix}-logs-bucket"
}
resource "aws_s3_bucket_ownership_controls" "logs_bucket_ownership" {
count = var.create_logs_bucket == true ? 1 : 0
bucket = aws_s3_bucket.logs_bucket[0].id
rule {
object_ownership = "BucketOwnerPreferred"
}
}
resource "aws_s3_bucket_acl" "logs_bucket_acl" {
count = var.create_logs_bucket == true ? 1 : 0
bucket = aws_s3_bucket.logs_bucket[0].id
acl = "private"
depends_on = [aws_s3_bucket_ownership_controls.logs_bucket_ownership[0]]
}
data "aws_iam_policy_document" "allow_access_from_eks" {
count = var.create_logs_bucket == true ? 1 : 0
statement {
effect = "Allow"
principals {
type = "AWS"
identifiers = ["arn:aws:iam::${var.load_balancer_account_id}:root"]
}
actions = [
"s3:PutObject"
]
resources = [
"${aws_s3_bucket.logs_bucket[0].arn}/*"
]
}
}
resource "aws_s3_bucket_policy" "allow_access_from_eks" {
count = var.create_logs_bucket == true ? 1 : 0
bucket = aws_s3_bucket.logs_bucket[0].id
policy = data.aws_iam_policy_document.allow_access_from_eks[0].json
}