-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
opensearch.tf
175 lines (137 loc) · 4 KB
/
opensearch.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
data "aws_availability_zones" "available" {}
locals {
region = data.aws_region.current.name
name = "es-${var.es_application_name}"
ideal_subnet_count = var.es_instance_count > 2 ? min(length(module.network.private_subnet_ids), 3) : var.es_instance_count
}
resource "aws_iam_service_linked_role" "elasticsearch" {
count = var.elasticsearch_enabled ? 1 : 0
aws_service_name = "es.amazonaws.com"
}
################################################################################
# OpenSearch Module
################################################################################
module "opensearch" {
count = var.elasticsearch_enabled ? 1 : 0
source = "./modules/opensearch"
# Domain
advanced_options = {
"rest.action.multi.allow_explicit_index" = "true"
}
advanced_security_options = {
enabled = false
anonymous_auth_enabled = true
internal_user_database_enabled = true
master_user_options = {
master_user_name = "admin"
master_user_password = random_password.es.result
}
}
auto_tune_options = {
desired_state = "ENABLED"
maintenance_schedule = [
{
start_at = "2028-05-13T07:44:12Z"
cron_expression_for_recurrence = "cron(0 0 ? * 1 *)"
duration = {
value = "2"
unit = "HOURS"
}
}
]
rollback_on_disable = "NO_ROLLBACK"
}
cluster_config = {
instance_count = var.es_instance_count
dedicated_master_enabled = true
dedicated_master_type = var.es_dedicated_master_type
instance_type = coalesce(var.es_instance_type, var.es_dedicated_master_type)
zone_awareness_config = {
availability_zone_count = local.ideal_subnet_count
}
zone_awareness_enabled = true
}
domain_endpoint_options = {
enforce_https = true
tls_security_policy = "Policy-Min-TLS-1-2-2019-07"
}
domain_name = local.name
ebs_options = {
ebs_enabled = true
iops = var.es_ebs_iops
throughput = 125
volume_type = var.es_volume_type
volume_size = var.es_volume_size
}
encrypt_at_rest = {
enabled = true
}
engine_version = var.es_engine_version
log_publishing_options = [
{ log_type = "INDEX_SLOW_LOGS" },
{ log_type = "SEARCH_SLOW_LOGS" },
]
application_name = local.name
admin_principals = var.es_admin_principals
read_principals = var.es_read_principals
node_to_node_encryption = {
enabled = true
}
vpc_options = {
subnet_ids = slice(module.network.private_subnet_ids, 0, min(length(module.network.private_subnet_ids), local.ideal_subnet_count))
}
# Security Group rule example
security_group_rules = {
ingress_443 = {
type = "ingress"
description = "HTTPS access from VPC"
from_port = 443
to_port = 443
ip_protocol = "tcp"
cidr_ipv4 = module.network.vpc.cidr_block
}
}
# Access policy
access_policy_statements = [
{
effect = "Allow"
principals = [{
type = "*"
identifiers = ["*"]
}]
actions = ["es:*"]
condition = [{
test = "IpAddress"
variable = "aws:SourceIp"
values = ["127.0.0.1/32"]
}]
}
]
tags = var.tags
depends_on = [aws_iam_service_linked_role.elasticsearch]
}
resource "random_password" "es" {
length = 128
special = false
}
data "aws_iam_policy_document" "ecs_osis_access" {
statement {
sid = "AllowOpensearchAccess"
resources = ["*"]
actions = [
"ec2:*",
"osis:*",
]
}
}
module "es_pod_policy" {
count = var.elasticsearch_enabled ? 1 : 0
source = "github.com/thoughtbot/flightdeck//aws/service-account-policy?ref=v0.9.0"
name = "es-${var.es_application_name}-pods"
policy_documents = concat(
module.opensearch[0][*].policy_json,
[data.aws_iam_policy_document.ecs_osis_access.json]
)
role_names = [module.pod_role.name]
}
data "aws_region" "current" {}