This repository has been archived by the owner on Sep 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
75 lines (62 loc) · 1.58 KB
/
main.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
locals {
tags = {
TieredStorage = "enabled"
AutoExpire = "true"
ExpiresIn = var.expiration_days
}
}
resource "aws_s3_bucket" "default" {
bucket = var.bucket
acl = "private"
force_destroy = false
tags = merge(local.tags, var.tags)
lifecycle_rule {
id = "tiered"
enabled = true
tags = {
Rule = "tiered"
AutoClean = "true"
Description = "Transitions the objects between storage classes, until eventual expiration."
}
transition {
days = var.standard_transition_days
storage_class = "STANDARD_IA"
}
transition {
days = var.glacier_transition_days
storage_class = "GLACIER"
}
expiration {
days = var.expiration_days
}
}
}
resource "aws_s3_bucket_policy" "default" {
bucket = aws_s3_bucket.default.id
policy = data.aws_iam_policy_document.default.json
}
data "aws_iam_policy_document" "default" {
statement {
sid = "ForceSSLOnlyAccess"
effect = "Deny"
actions = ["s3:GetObject"]
resources = ["${aws_s3_bucket.default.arn}/*"]
principals {
type = "AWS"
identifiers = ["*"]
}
condition {
test = "Bool"
variable = "aws:SecureTransport"
values = ["false"]
}
}
}
resource "aws_s3_bucket_public_access_block" "default" {
bucket = aws_s3_bucket.default.id
block_public_acls = true
ignore_public_acls = true
block_public_policy = true
restrict_public_buckets = true
depends_on = ["aws_s3_bucket_policy.default"]
}