-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paths3.tf
68 lines (52 loc) · 1.54 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
module "origin_bucket" {
source = "terraform-aws-modules/s3-bucket/aws"
bucket = "myorigin-${random_pet.bucket_name.id}"
acl = "private"
versioning = {
enabled = true
}
}
resource "aws_s3_bucket_policy" "cdn-cf-policy" {
bucket = module.origin_bucket.s3_bucket_id
policy = data.aws_iam_policy_document.my-cdn-cf-policy.json
}
data "aws_iam_policy_document" "my-cdn-cf-policy" {
statement {
sid = "1"
principals {
type = "AWS"
identifiers = module.cdn.cloudfront_origin_access_identity_iam_arns
}
actions = [
"s3:GetObject"
]
resources = [
"${module.origin_bucket.s3_bucket_arn}/*"
]
}
}
resource "aws_s3_object" "index" {
bucket = module.origin_bucket.s3_bucket_id
key = "index.html"
source = "${path.module}/files/index.html"
content_type = "text/html"
etag = filemd5("${path.module}/files/index.html")
}
resource "aws_s3_object" "global" {
bucket = module.origin_bucket.s3_bucket_id
key = "flag.png"
source = "${path.module}/files/flag.png"
content_type = "image/png"
etag = filemd5("${path.module}/files/flag.png")
}
locals {
countries = toset(["CA", "ES", "IT", "JP", "TR", "US"])
}
resource "aws_s3_object" "countries_flag" {
for_each = local.countries
bucket = module.origin_bucket.s3_bucket_id
key = "${each.key}/flag.png"
source = "${path.module}/files/flag_${each.key}.png"
content_type = "image/png"
etag = filemd5("${path.module}/files/flag_${each.key}.png")
}