-
Notifications
You must be signed in to change notification settings - Fork 0
/
storage.tf
80 lines (72 loc) · 2.13 KB
/
storage.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
resource "aws_s3_bucket" "static_site" {
bucket = "cc-static-site-${var.tenant_vars.product}-${var.tenant_vars.component}"
tags = local.common_tags
}
resource "aws_s3_bucket_public_access_block" "static_site_acl" {
bucket = aws_s3_bucket.static_site.id
block_public_acls = true
block_public_policy = true
ignore_public_acls = true
restrict_public_buckets = true
}
resource "aws_s3_bucket_versioning" "static_site_versioning" {
bucket = aws_s3_bucket.static_site.id
versioning_configuration {
status = "Enabled"
}
}
resource "aws_s3_bucket_server_side_encryption_configuration" "static_site_encryption" {
bucket = aws_s3_bucket.static_site.id
rule {
apply_server_side_encryption_by_default {
kms_master_key_id = aws_kms_key.static_site_kms.arn
sse_algorithm = "aws:kms"
}
bucket_key_enabled = true
}
}
data "aws_iam_policy_document" "static_site_iam_storage_policy_document" {
statement {
sid = "AllowCloudFrontServicePrincipalReadOnly"
effect = "Allow"
principals {
type = "Service"
identifiers = ["cloudfront.amazonaws.com"]
}
actions = [
"s3:GetObject"
]
resources = [
"arn:aws:s3:::${aws_s3_bucket.static_site.id}/*"
]
condition {
test = "StringEquals"
variable = "aws:SourceArn"
values = [aws_cloudfront_distribution.static_site_distribution.arn]
}
}
statement {
sid = "AllowCloudFrontServicePrincipalListBucket"
effect = "Allow"
principals {
type = "Service"
identifiers = ["cloudfront.amazonaws.com"]
}
actions = [
"s3:ListBucket"
]
resources = [
"arn:aws:s3:::${aws_s3_bucket.static_site.id}"
]
condition {
test = "StringEquals"
variable = "aws:SourceArn"
values = [aws_cloudfront_distribution.static_site_distribution.arn]
}
}
}
resource "aws_s3_bucket_policy" "static_site_policy" {
bucket = aws_s3_bucket.static_site.id
policy = data.aws_iam_policy_document.static_site_iam_storage_policy_document.json
depends_on = [aws_s3_bucket_public_access_block.static_site_acl]
}