-
Notifications
You must be signed in to change notification settings - Fork 29
/
main.tf
111 lines (89 loc) · 2.96 KB
/
main.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
resource "aws_security_group" "elasticsearch" {
name = var.name
description = "Security Group to allow traffic to ElasticSearch"
vpc_id = var.vpc_id
}
resource "aws_security_group_rule" "secure_cidrs" {
count = length(var.ingress_allow_cidr_blocks) > 0 ? 1 : 0
type = "ingress"
from_port = 443
to_port = 443
protocol = "TCP"
cidr_blocks = var.ingress_allow_cidr_blocks
security_group_id = aws_security_group.elasticsearch.id
}
resource "aws_security_group_rule" "secure_sgs" {
count = length(var.ingress_allow_security_groups)
type = "ingress"
from_port = 443
to_port = 443
protocol = "tcp"
source_security_group_id = element(var.ingress_allow_security_groups, count.index)
security_group_id = aws_security_group.elasticsearch.id
}
resource "aws_security_group_rule" "egress_all" {
type = "egress"
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
security_group_id = aws_security_group.elasticsearch.id
}
# https://github.com/terraform-providers/terraform-provider-aws/issues/5218
resource "aws_iam_service_linked_role" "default" {
count = var.create_iam_service_linked_role ? 1 : 0
aws_service_name = "es.amazonaws.com"
description = "AWSServiceRoleForAmazonElasticsearchService Service-Linked Role"
}
resource "aws_elasticsearch_domain" "es" {
domain_name = var.name
elasticsearch_version = var.elasticsearch_version
encrypt_at_rest {
enabled = var.encryption_enabled
kms_key_id = var.encryption_kms_key_id
}
cluster_config {
instance_type = var.itype
instance_count = var.icount
dedicated_master_enabled = var.dedicated_master
dedicated_master_type = var.mtype
dedicated_master_count = var.mcount
zone_awareness_enabled = var.zone_awareness
zone_awareness_config {
availability_zone_count = length(var.subnet_ids) > 2 ? 3 : 2
}
}
access_policies = var.access_policies
vpc_options {
security_group_ids = [aws_security_group.elasticsearch.id]
subnet_ids = var.subnet_ids
}
advanced_options = {
"rest.action.multi.allow_explicit_index" = var.rest_action_multi_allow_explicit_index
"indices.fielddata.cache.size" = var.indices_fielddata_cache_size
"indices.query.bool.max_clause_count" = var.indices_query_bool_max_clause_count
}
ebs_options {
ebs_enabled = true
volume_type = var.volume_type
volume_size = var.volume_size
}
snapshot_options {
automated_snapshot_start_hour = var.snapshot_start
}
tags = {
Domain = var.name
}
depends_on = [
aws_iam_service_linked_role.default,
]
}
# Add ALB record on DNS
resource "aws_route53_record" "main" {
count = length(var.zone_id) > 0 ? 1 : 0
zone_id = var.zone_id
name = var.name
type = "CNAME"
ttl = "300"
records = [aws_elasticsearch_domain.es.endpoint]
}