forked from telia-oss/terraform-aws-secure-baseline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paths3-bucket.tf
72 lines (62 loc) · 1.81 KB
/
s3-bucket.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
resource "aws_s3_bucket" "S3SharedBucket" {
bucket = var.s3_bucket_name
acl = "log-delivery-write"
force_destroy = var.force_destroy
server_side_encryption_configuration {
rule {
apply_server_side_encryption_by_default {
sse_algorithm = "AES256"
}
}
}
logging {
target_bucket = var.s3_bucket_name
target_prefix = var.s3_key_prefix
}
lifecycle_rule {
id = "auto-archive"
enabled = true
transition {
days = var.lifecycle_glacier_transition_days
storage_class = "GLACIER"
}
expiration {
days = var.s3_bucket_expiration_days
}
}
}
resource "aws_s3_bucket_public_access_block" "blockPublicAccess" {
bucket = aws_s3_bucket.S3SharedBucket.id
block_public_acls = true
block_public_policy = true
depends_on = [aws_s3_bucket_policy.BucketPolicy]
}
data "aws_iam_policy_document" "s3-bucket-policy-forS3SharedBucket" {
statement {
actions = ["s3:GetBucketAcl"]
effect = "Allow"
resources = ["arn:aws:s3:::${var.s3_bucket_name}"]
principals {
type = "Service"
identifiers = ["cloudtrail.amazonaws.com", "config.amazonaws.com"]
}
}
statement {
actions = ["s3:PutObject"]
effect = "Allow"
resources = ["arn:aws:s3:::${var.s3_bucket_name}/${var.s3_key_prefix}/AWSLogs/${var.aws_account_id}/*"]
principals {
type = "Service"
identifiers = ["cloudtrail.amazonaws.com", "config.amazonaws.com"]
}
condition {
test = "StringEquals"
variable = "s3:x-amz-acl"
values = ["bucket-owner-full-control"]
}
}
}
resource "aws_s3_bucket_policy" "BucketPolicy" {
bucket = aws_s3_bucket.S3SharedBucket.id
policy = data.aws_iam_policy_document.s3-bucket-policy-forS3SharedBucket.json
}