-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloudfront.tf
116 lines (100 loc) · 2.73 KB
/
cloudfront.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
resource "aws_cloudfront_distribution" "this" {
origin {
domain_name = "${aws_s3_bucket.backup_bucket.bucket}.s3.amazonaws.com"
origin_id = "example-origin"
}
default_cache_behavior {
allowed_methods = ["GET", "HEAD"]
cached_methods = ["GET", "HEAD"]
target_origin_id = "example-origin"
viewer_protocol_policy = "allow-all"
realtime_log_config_arn = aws_cloudfront_realtime_log_config.cloudfront_dynatrace_monitoring.arn
forwarded_values {
query_string = false
cookies {
forward = "none"
}
}
}
enabled = true
is_ipv6_enabled = true
default_root_object = "index.html"
restrictions {
geo_restriction {
restriction_type = "none"
}
}
viewer_certificate {
cloudfront_default_certificate = true
}
}
resource "aws_cloudfront_monitoring_subscription" "additional_metrics" {
distribution_id = aws_cloudfront_distribution.this.id
monitoring_subscription {
realtime_metrics_subscription_config {
realtime_metrics_subscription_status = "Enabled"
}
}
}
resource "aws_iam_role" "cloudfront_dynatrace_role" {
name = "${local.name_prefix}-cloudfront-dynatrace-monitoring-role"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = "sts:AssumeRole"
Effect = "Allow"
Principal = {
Service = "cloudfront.amazonaws.com"
}
}
]
})
}
data "aws_iam_policy_document" "cloudfront_dynatrace_policy_document" {
statement {
effect = "Allow"
actions = [
"kinesis:DescribeStreamSummary",
"kinesis:DescribeStream",
"kinesis:ListStreams",
"kinesis:PutRecord",
"kinesis:PutRecords"
]
resources = [aws_kinesis_stream.dynatrace_kinesis_stream.arn]
}
statement {
effect = "Allow"
actions = ["kms:GenerateDataKey"]
resources = [local.local_key_arn]
}
}
resource "aws_iam_role_policy" "cloudfront_policy" {
name = "${local.name_prefix}-cloudfront-dynatrace-policy"
role = aws_iam_role.cloudfront_dynatrace_role.id
policy = data.aws_iam_policy_document.cloudfront_dynatrace_policy_document.json
}
resource "aws_cloudfront_realtime_log_config" "cloudfront_dynatrace_monitoring" {
name = "${local.name_prefix}-cloudfront-dynatrace-monitoring"
sampling_rate = 100
fields = [
"timestamp",
"c-ip",
"sc-status",
"cs-method",
"cs-protocol",
"cs-host",
"cs-uri-stem",
"x-host-header",
"time-taken",
"cs-user-agent",
"cs-cookie"
]
endpoint {
stream_type = "Kinesis"
kinesis_stream_config {
role_arn = aws_iam_role.cloudfront_dynatrace_role.arn
stream_arn = aws_kinesis_stream.dynatrace_kinesis_stream.arn
}
}
}