-
Notifications
You must be signed in to change notification settings - Fork 0
/
elasticsearch.tf
87 lines (78 loc) · 2.24 KB
/
elasticsearch.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
# The CloudWatch log group where application logs will be written
resource "aws_cloudwatch_log_group" "es_logs" {
name = "/aws/aes/domains/${var.elasticsearch_domain_name}/application-logs"
retention_in_days = 30
}
# IAM policy document that that allows ES to write to CloudWatch logs
data "aws_iam_policy_document" "es_cloudwatch_doc" {
statement {
actions = [
"logs:PutLogEvents",
"logs:CreateLogStream",
]
effect = "Allow"
principals {
identifiers = ["es.amazonaws.com"]
type = "Service"
}
resources = [
aws_cloudwatch_log_group.es_logs.arn,
"${aws_cloudwatch_log_group.es_logs.arn}:*",
]
}
}
resource "aws_cloudwatch_log_resource_policy" "es_cloudwatch_policy" {
policy_document = data.aws_iam_policy_document.es_cloudwatch_doc.json
policy_name = "dmarc-import-es-cloudwatch-policy"
}
# Policy document that allows authenticated Cognito users access to the
# Elasticsearch domain
data "aws_iam_policy_document" "es_cognito_auth" {
statement {
actions = [
"es:*",
]
effect = "Allow"
principals {
identifiers = [
aws_iam_role.cognito_authenticated.arn,
]
type = "AWS"
}
resources = [
"arn:aws:es:${var.aws_region}:*:domain/${var.elasticsearch_domain_name}/*",
]
}
}
# The Elasticsearch domain
resource "aws_elasticsearch_domain" "es" {
access_policies = data.aws_iam_policy_document.es_cognito_auth.json
domain_name = var.elasticsearch_domain_name
elasticsearch_version = "OpenSearch_1.3"
cluster_config {
instance_type = "m6g.large.elasticsearch"
instance_count = 3
zone_awareness_config {
availability_zone_count = 3
}
zone_awareness_enabled = true
}
cognito_options {
enabled = true
identity_pool_id = aws_cognito_identity_pool.dmarc.id
role_arn = aws_iam_role.opensearch_cognito.arn
user_pool_id = aws_cognito_user_pool.dmarc.id
}
ebs_options {
ebs_enabled = true
volume_size = 100
volume_type = "gp2"
}
encrypt_at_rest {
enabled = true
}
log_publishing_options {
cloudwatch_log_group_arn = aws_cloudwatch_log_group.es_logs.arn
log_type = "ES_APPLICATION_LOGS"
}
}