-
-
Notifications
You must be signed in to change notification settings - Fork 146
Expand file tree
/
Copy pathmain.tf
More file actions
98 lines (80 loc) · 1.98 KB
/
Copy pathmain.tf
File metadata and controls
98 lines (80 loc) · 1.98 KB
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
94
95
96
97
98
resource "aws_s3_bucket" "logs" {
bucket_prefix = "fastly-logs-"
lifecycle_rule {
enabled = true
expiration {
days = 365
}
}
lifecycle_rule {
id = "move-to-glacier"
enabled = true
transition {
days = 14
storage_class = "DEEP_ARCHIVE"
}
}
}
resource "aws_s3_bucket_policy" "logs" {
bucket = aws_s3_bucket.logs.id
policy = <<EOF
{
"Version": "2008-10-17",
"Statement": [
{
"Sid": "AllowNixOSOrgRead",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::008826681144:user/eelco.dolstra",
"AWS": "arn:aws:iam::008826681144:user/fastly-log-processor"
},
"Action": [
"s3:GetObject",
"s3:ListBucket"
],
"Resource": [
"arn:aws:s3:::${aws_s3_bucket.logs.id}/*",
"arn:aws:s3:::${aws_s3_bucket.logs.id}"
]
}
]
}
EOF
}
resource "aws_iam_role" "fastly_log_forwarder" {
name = "FastlyLogForwarder"
path = "/system/"
assume_role_policy = data.aws_iam_policy_document.assume_role_policy.json
}
resource "aws_iam_policy" "policy" {
name_prefix = "FastlyLogForwarder"
path = "/system/"
description = "Allow Fastly to write logs to ${aws_s3_bucket.logs.bucket}."
policy = data.aws_iam_policy_document.fastly_write.json
}
resource "aws_iam_role_policy_attachment" "attachment" {
role = aws_iam_role.fastly_log_forwarder.name
policy_arn = aws_iam_policy.policy.arn
}
data "aws_iam_policy_document" "assume_role_policy" {
statement {
actions = ["sts:AssumeRole"]
condition {
test = "StringEquals"
variable = "sts:ExternalId"
# this is our Fastly customer ID
values = [var.fastly_customer_id]
}
principals {
type = "AWS"
# This is the ID of the Fastly AWS account
identifiers = ["717331877981"]
}
}
}
data "aws_iam_policy_document" "fastly_write" {
statement {
actions = ["s3:PutObject"]
resources = ["${aws_s3_bucket.logs.arn}/*"]
}
}