-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy paths3.tf
77 lines (63 loc) · 1.74 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT-0
resource "aws_s3_bucket" "this" {
bucket = "${var.pipeline_name}-artifacts-${data.aws_caller_identity.current.account_id}"
force_destroy = true
}
resource "aws_s3_bucket_public_access_block" "this" {
bucket = aws_s3_bucket.this.id
block_public_acls = true
block_public_policy = true
ignore_public_acls = true
restrict_public_buckets = true
}
resource "aws_s3_bucket_server_side_encryption_configuration" "this" {
bucket = aws_s3_bucket.this.bucket
rule {
apply_server_side_encryption_by_default {
kms_master_key_id = try(var.kms_key, null)
sse_algorithm = var.kms_key == null ? "AES256" : "aws:kms"
}
}
}
resource "aws_s3_bucket_policy" "this" {
bucket = aws_s3_bucket.this.id
policy = data.aws_iam_policy_document.this.json
}
data "aws_iam_policy_document" "this" {
statement {
effect = "Deny"
principals {
type = "AWS"
identifiers = ["*"]
}
actions = [
"s3:*",
]
resources = [
"${aws_s3_bucket.this.arn}/*",
"${aws_s3_bucket.this.arn}"
]
condition {
test = "Bool"
values = ["false"]
variable = "aws:SecureTransport"
}
}
}
resource "aws_s3_bucket_lifecycle_configuration" "this" {
bucket = aws_s3_bucket.this.id
rule {
status = "Enabled"
id = "${var.artifact_retention}-days"
expiration {
days = var.artifact_retention
}
}
}
resource "aws_s3_bucket_logging" "this" {
count = var.access_logging_bucket == null ? 0 : 1
bucket = aws_s3_bucket.this.id
target_bucket = var.access_logging_bucket
target_prefix = "${aws_s3_bucket.this.id}/"
}