-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paths3.tf
70 lines (59 loc) · 1.46 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
# プライベートバケット
resource "aws_s3_bucket" "private" {
bucket = "private-pragmatic-terraform-yokota"
versioning {
enabled = true
}
server_side_encryption_configuration {
rule {
apply_server_side_encryption_by_default {
sse_algorithm = "AES256"
}
}
}
}
# ブロックパブリックアクセス
resource "aws_s3_bucket_public_access_block" "private" {
bucket = aws_s3_bucket.private.id
block_public_acls = true
block_public_policy = true
ignore_public_acls = true
restrict_public_buckets = true
}
# パブリックバケット
resource "aws_s3_bucket" "public" {
bucket = "public-pragmatic-terraform-yokota"
acl = "public-read"
cors_rule {
allowed_origins = ["https://example.com"]
allowed_methods = ["GET"]
allowed_headers = ["*"]
max_age_seconds = 3000
}
}
# ログローテーションバケット
resource "aws_s3_bucket" "alb_log" {
bucket = "alb-log-pragmatic-terraform-yokota"
lifecycle_rule {
enabled = true
expiration {
days = "180"
}
}
}
# バケットポリシー
resource "aws_s3_bucket_policy" "alb_log" {
bucket = aws_s3_bucket.alb_log.id
policy = data.aws_iam_policy_document.alb_log.json
}
data "aws_iam_policy_document" "alb_log" {
statement {
effect = "Allow"
actions = ["s3:PutObject"]
resources = ["arn:aws:s3:::${aws_s3_bucket.alb_log.id}/*"]
principals {
type = "AWS"
identifiers = ["582318560864"]
}
}
}