-
Notifications
You must be signed in to change notification settings - Fork 0
/
s3_bucket.tf
93 lines (80 loc) · 2.18 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
resource "aws_s3_bucket" "terraform_state" {
bucket = var.bucket_name
tags = var.s3_tags
}
resource "aws_s3_bucket_server_side_encryption_configuration" "terraform_state" {
bucket = aws_s3_bucket.terraform_state.bucket
rule {
bucket_key_enabled = false
apply_server_side_encryption_by_default {
kms_master_key_id = var.s3_encryption_key
sse_algorithm = "aws:kms"
}
}
}
resource "aws_s3_bucket_public_access_block" "terraform_state" {
bucket = aws_s3_bucket.terraform_state.id
block_public_acls = true
block_public_policy = true
ignore_public_acls = true
restrict_public_buckets = true
}
resource "aws_s3_bucket_versioning" "terraform_state" {
bucket = aws_s3_bucket.terraform_state.id
versioning_configuration {
status = "Enabled"
}
}
resource "aws_s3_bucket_lifecycle_configuration" "terraform_state" {
bucket = aws_s3_bucket.terraform_state.bucket
rule {
id = "delete_noncurrent_versions_after_900_days"
status = "Enabled"
abort_incomplete_multipart_upload {
days_after_initiation = 3
}
noncurrent_version_expiration {
noncurrent_days = 900
}
expiration {
days = 0
expired_object_delete_marker = true
}
}
}
data "aws_caller_identity" "current" {}
resource "aws_s3_bucket_policy" "terraform_state_policy" {
bucket = aws_s3_bucket.terraform_state.id
policy = jsonencode({
"Version" : "2012-10-17",
"Statement" : [
{
"Sid" : "EnforcedTLS",
"Effect" : "Deny",
"Principal" : "*",
"Action" : "s3:*",
"Resource" : [
aws_s3_bucket.terraform_state.arn,
"${aws_s3_bucket.terraform_state.arn}/*"
],
"Condition" : {
"Bool" : {
"aws:SecureTransport" : "false"
}
}
},
{
"Sid" : "RootAccess",
"Effect" : "Allow",
"Principal" : {
"AWS" : "arn:aws:iam::${data.aws_caller_identity.current.account_id}:root"
},
"Action" : "s3:*",
"Resource" : [
aws_s3_bucket.terraform_state.arn,
"${aws_s3_bucket.terraform_state.arn}/*"
]
}
]
})
}