forked from terraform-community-modules/tf_aws_elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.tf
88 lines (71 loc) · 2.38 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
# Elasticsearch domain
data "aws_iam_policy_document" "es_management_access" {
count = "${length(var.vpc_options["subnet_ids"]) > 0 ? 0 : 1}"
statement {
actions = [
"es:*",
]
resources = [
"${aws_elasticsearch_domain.es.arn}",
"${aws_elasticsearch_domain.es.arn}/*",
]
principals {
type = "AWS"
identifiers = ["*"]
}
condition {
test = "IpAddress"
variable = "aws:SourceIp"
values = ["${distinct(compact(var.management_public_ip_addresses))}"]
}
}
statement {
actions = [
"es:ESHttpDelete",
"es:ESHttpGet",
"es:ESHttpHead",
"es:ESHttpPost",
"es:ESHttpPut"
]
resources = [
"${aws_elasticsearch_domain.es.arn}",
"${aws_elasticsearch_domain.es.arn}/*",
]
principals {
type = "AWS"
identifiers = ["${distinct(compact(var.shipper_iam_roles))}"]
}
}
}
resource "aws_elasticsearch_domain" "es" {
count = "${length(var.vpc_options["subnet_ids"]) > 0 ? 0 : 1}"
domain_name = "${local.domain_name}"
elasticsearch_version = "${var.es_version}"
cluster_config {
instance_type = "${var.instance_type}"
instance_count = "${var.instance_count}"
dedicated_master_enabled = "${var.instance_count >= var.dedicated_master_threshold ? true : false}"
dedicated_master_count = "${var.instance_count >= var.dedicated_master_threshold ? 3 : 0}"
dedicated_master_type = "${var.instance_count >= var.dedicated_master_threshold ? (var.dedicated_master_type != "false" ? var.dedicated_master_type : var.instance_type) : ""}"
zone_awareness_enabled = "${var.es_zone_awareness}"
}
# advanced_options {
# }
ebs_options {
ebs_enabled = "${var.ebs_volume_size > 0 ? true : false}"
volume_size = "${var.ebs_volume_size}"
volume_type = "${var.ebs_volume_type}"
}
snapshot_options {
automated_snapshot_start_hour = "${var.snapshot_start_hour}"
}
tags = "${merge(var.tags, map(
"Domain", "${local.domain_name}"
))}"
}
resource "aws_elasticsearch_domain_policy" "es_management_access" {
count = "${length(var.vpc_options["subnet_ids"]) > 0 ? 0 : 1}"
domain_name = "${local.domain_name}"
access_policies = "${data.aws_iam_policy_document.es_management_access.json}"
}
# vim: set et fenc= ff=unix ft=terraform sts=2 sw=2 ts=2 :