Skip to content

Commit 5026e88

Browse files
author
Nikita Dugar
authored
Merge pull request #6 from clouddrove/CD-120
Add public option
2 parents 840d2e0 + c8ace7f commit 5026e88

File tree

4 files changed

+160
-17
lines changed

4 files changed

+160
-17
lines changed

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
Terraform AWS Elasticsearch
88
</h1>
99

10-
<p align="center" style="font-size: 1.2rem;">
10+
<p align="center" style="font-size: 1.2rem;">
1111
Terraform module to create an Elasticsearch resource on AWS.
1212
</p>
1313

@@ -38,7 +38,7 @@
3838
<hr>
3939

4040

41-
We eat, drink, sleep and most importantly love **DevOps**. We are working towards strategies for standardizing architecture while ensuring security for the infrastructure. We are strong believer of the philosophy <b>Bigger problems are always solved by breaking them into smaller manageable problems</b>. Resonating with microservices architecture, it is considered best-practice to run database, cluster, storage in smaller <b>connected yet manageable pieces</b> within the infrastructure.
41+
We eat, drink, sleep and most importantly love **DevOps**. We are working towards strategies for standardizing architecture while ensuring security for the infrastructure. We are strong believer of the philosophy <b>Bigger problems are always solved by breaking them into smaller manageable problems</b>. Resonating with microservices architecture, it is considered best-practice to run database, cluster, storage in smaller <b>connected yet manageable pieces</b> within the infrastructure.
4242

4343
This module is basically combination of [Terraform open source](https://www.terraform.io/) and includes automatation tests and examples. It also helps to create and improve your infrastructure with minimalistic code instead of maintaining the whole infrastructure code yourself.
4444

@@ -49,7 +49,7 @@ We have [*fifty plus terraform modules*][terraform_modules]. A few of them are c
4949

5050
## Prerequisites
5151

52-
This module has a few dependencies:
52+
This module has a few dependencies:
5353

5454
- [Terraform 0.13](https://learn.hashicorp.com/terraform/getting-started/install.html)
5555
- [Go](https://golang.org/doc/install)
@@ -180,8 +180,9 @@ Note: There are some type of instances which not support encryption and EBS opti
180180
| log\_publishing\_search\_enabled | Specifies whether log publishing option for SEARCH\_SLOW\_LOGS is enabled or not. | `bool` | `false` | no |
181181
| managedby | ManagedBy, eg 'CloudDrove' or 'AnmolNagpal'. | `string` | `"anmol@clouddrove.com"` | no |
182182
| name | Name (e.g. `app` or `cluster`). | `string` | `""` | no |
183-
| security\_group\_ids | Security Group IDs. | `list(string)` | n/a | yes |
184-
| subnet\_ids | Subnet IDs. | `list(string)` | n/a | yes |
183+
| public\_enabled | Enable Elasticsearch cluster is public or not. | `bool` | `false` | no |
184+
| security\_group\_ids | Security Group IDs. | `list(string)` | `[]` | no |
185+
| subnet\_ids | Subnet IDs. | `list(string)` | `[]` | no |
185186
| tags | Additional tags (e.g. map(`BusinessUnit`,`XYZ`). | `map` | `{}` | no |
186187
| tls\_security\_policy | The name of the TLS security policy that needs to be applied to the HTTPS endpoint. | `any` | `null` | no |
187188
| ttl | The TTL of the record to add to the DNS zone to complete certificate validation. | `string` | `"300"` | no |
@@ -201,7 +202,7 @@ Note: There are some type of instances which not support encryption and EBS opti
201202

202203

203204
## Testing
204-
In this module testing is performed with [terratest](https://github.com/gruntwork-io/terratest) and it creates a small piece of infrastructure, matches the output like ARN, ID and Tags name etc and destroy infrastructure in your AWS account. This testing is written in GO, so you need a [GO environment](https://golang.org/doc/install) in your system.
205+
In this module testing is performed with [terratest](https://github.com/gruntwork-io/terratest) and it creates a small piece of infrastructure, matches the output like ARN, ID and Tags name etc and destroy infrastructure in your AWS account. This testing is written in GO, so you need a [GO environment](https://golang.org/doc/install) in your system.
205206

206207
You need to run the following command in the testing folder:
207208
```hcl
@@ -210,7 +211,7 @@ You need to run the following command in the testing folder:
210211

211212

212213

213-
## Feedback
214+
## Feedback
214215
If you come accross a bug or have any feedback, please log it in our [issue tracker](https://github.com/clouddrove/terraform-aws-elasticsearch/issues), or feel free to drop us an email at [hello@clouddrove.com](mailto:hello@clouddrove.com).
215216

216217
If you have found it worth your time, go ahead and give us a ★ on [our GitHub](https://github.com/clouddrove/terraform-aws-elasticsearch)!

_example/single-node/example.tf

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,13 @@ module "elasticsearch" {
6565
log_publishing_search_cloudwatch_log_group_arn = true
6666
log_publishing_index_cloudwatch_log_group_arn = true
6767

68-
dns_enabled = false
69-
es_hostname = "es"
70-
kibana_hostname = "kibana"
71-
dns_zone_id = false
68+
enforce_https = true
69+
tls_security_policy = "Policy-Min-TLS-1-0-2019-07"
70+
public_enabled = false
71+
dns_enabled = false
72+
es_hostname = "es"
73+
kibana_hostname = "kibana"
74+
dns_zone_id = "Z1XJD7SSBKXLC1"
7275

7376
advanced_options = {
7477
"rest.action.multi.allow_explicit_index" = "true"

main.tf

Lines changed: 137 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ data "aws_iam_policy_document" "elasticsearch-log-publishing-policy" {
8585
#Module : Elasticsearch
8686
#Description : Terraform module to create Elasticsearch resource on AWS.
8787
resource "aws_elasticsearch_domain" "default" {
88-
count = var.enabled && var.zone_awareness_enabled ? 1 : 0
88+
count = var.enabled && var.zone_awareness_enabled && var.public_enabled == false ? 1 : 0
8989
domain_name = var.domain_name != "" ? var.domain_name : module.labels.id
9090
elasticsearch_version = var.elasticsearch_version
9191

@@ -157,10 +157,78 @@ resource "aws_elasticsearch_domain" "default" {
157157
depends_on = [aws_iam_service_linked_role.default]
158158
}
159159

160+
resource "aws_elasticsearch_domain" "default-public" {
161+
count = var.enabled && var.zone_awareness_enabled && var.public_enabled ? 1 : 0
162+
domain_name = var.domain_name != "" ? var.domain_name : module.labels.id
163+
elasticsearch_version = var.elasticsearch_version
164+
165+
advanced_options = var.advanced_options
166+
167+
ebs_options {
168+
ebs_enabled = var.volume_size > 0 ? true : false
169+
volume_size = var.volume_size
170+
volume_type = var.volume_type
171+
iops = var.iops
172+
}
173+
174+
encrypt_at_rest {
175+
enabled = false
176+
kms_key_id = var.kms_key_id
177+
}
178+
179+
cluster_config {
180+
instance_count = var.instance_count
181+
instance_type = var.instance_type
182+
dedicated_master_enabled = var.dedicated_master_enabled
183+
dedicated_master_count = var.dedicated_master_count
184+
dedicated_master_type = var.dedicated_master_type
185+
zone_awareness_enabled = var.zone_awareness_enabled
186+
187+
zone_awareness_config {
188+
availability_zone_count = var.availability_zone_count
189+
}
190+
}
191+
192+
node_to_node_encryption {
193+
enabled = var.encryption_enabled
194+
}
195+
196+
snapshot_options {
197+
automated_snapshot_start_hour = var.automated_snapshot_start_hour
198+
}
199+
200+
log_publishing_options {
201+
enabled = var.log_publishing_index_enabled
202+
log_type = "INDEX_SLOW_LOGS"
203+
cloudwatch_log_group_arn = format("%s:*", join("", aws_cloudwatch_log_group.cloudwatch.*.arn))
204+
}
205+
206+
log_publishing_options {
207+
enabled = var.log_publishing_search_enabled
208+
log_type = "SEARCH_SLOW_LOGS"
209+
cloudwatch_log_group_arn = format("%s:*", join("", aws_cloudwatch_log_group.cloudwatch.*.arn))
210+
}
211+
212+
log_publishing_options {
213+
enabled = var.log_publishing_application_enabled
214+
log_type = "ES_APPLICATION_LOGS"
215+
cloudwatch_log_group_arn = format("%s:*", join("", aws_cloudwatch_log_group.cloudwatch.*.arn))
216+
}
217+
218+
domain_endpoint_options {
219+
enforce_https = var.enforce_https
220+
tls_security_policy = var.tls_security_policy
221+
}
222+
223+
tags = module.labels.tags
224+
225+
depends_on = [aws_iam_service_linked_role.default]
226+
}
227+
160228
#Module : Elasticsearch
161229
#Description : Terraform module to create Elasticsearch resource on AWS.
162230
resource "aws_elasticsearch_domain" "single" {
163-
count = var.enabled && var.zone_awareness_enabled == false ? 1 : 0
231+
count = var.enabled && var.zone_awareness_enabled == false && var.public_enabled == false ? 1 : 0
164232
domain_name = var.domain_name != "" ? var.domain_name : module.labels.id
165233
elasticsearch_version = var.elasticsearch_version
166234

@@ -227,6 +295,69 @@ resource "aws_elasticsearch_domain" "single" {
227295
depends_on = [aws_iam_service_linked_role.default]
228296
}
229297

298+
resource "aws_elasticsearch_domain" "single-public" {
299+
count = var.enabled && var.zone_awareness_enabled == false && var.public_enabled ? 1 : 0
300+
domain_name = var.domain_name != "" ? var.domain_name : module.labels.id
301+
elasticsearch_version = var.elasticsearch_version
302+
303+
advanced_options = var.advanced_options
304+
305+
ebs_options {
306+
ebs_enabled = var.volume_size > 0 ? true : false
307+
volume_size = var.volume_size
308+
volume_type = var.volume_type
309+
iops = var.iops
310+
}
311+
312+
encrypt_at_rest {
313+
enabled = false
314+
kms_key_id = var.kms_key_id
315+
}
316+
317+
cluster_config {
318+
instance_count = var.instance_count
319+
instance_type = var.instance_type
320+
dedicated_master_enabled = var.dedicated_master_enabled
321+
dedicated_master_count = var.dedicated_master_count
322+
dedicated_master_type = var.dedicated_master_type
323+
}
324+
325+
node_to_node_encryption {
326+
enabled = var.encryption_enabled
327+
}
328+
329+
snapshot_options {
330+
automated_snapshot_start_hour = var.automated_snapshot_start_hour
331+
}
332+
333+
log_publishing_options {
334+
enabled = var.log_publishing_index_enabled
335+
log_type = "INDEX_SLOW_LOGS"
336+
cloudwatch_log_group_arn = format("%s:*", join("", aws_cloudwatch_log_group.cloudwatch.*.arn))
337+
}
338+
339+
log_publishing_options {
340+
enabled = var.log_publishing_search_enabled
341+
log_type = "SEARCH_SLOW_LOGS"
342+
cloudwatch_log_group_arn = format("%s:*", join("", aws_cloudwatch_log_group.cloudwatch.*.arn))
343+
}
344+
345+
log_publishing_options {
346+
enabled = var.log_publishing_application_enabled
347+
log_type = "ES_APPLICATION_LOGS"
348+
cloudwatch_log_group_arn = format("%s:*", join("", aws_cloudwatch_log_group.cloudwatch.*.arn))
349+
}
350+
351+
domain_endpoint_options {
352+
enforce_https = var.enforce_https
353+
tls_security_policy = var.tls_security_policy
354+
}
355+
356+
tags = module.labels.tags
357+
358+
depends_on = [aws_iam_service_linked_role.default]
359+
}
360+
230361
#Module : Elasticsearch Role Policy
231362
#Description : Terraform module to create Elasticsearch resource on AWS.
232363
data "aws_iam_policy_document" "default" {
@@ -236,8 +367,8 @@ data "aws_iam_policy_document" "default" {
236367
actions = distinct(compact(var.iam_actions))
237368

238369
resources = [
239-
var.zone_awareness_enabled ? join("", aws_elasticsearch_domain.default.*.arn) : join("", aws_elasticsearch_domain.single.*.arn),
240-
var.zone_awareness_enabled ? format("%s/*", join("", aws_elasticsearch_domain.default.*.arn)) : format("%s/*", join("", aws_elasticsearch_domain.single.*.arn))
370+
var.zone_awareness_enabled ? (var.public_enabled ? join("", aws_elasticsearch_domain.default-public.*.arn) : join("", aws_elasticsearch_domain.default.*.arn)) : (var.public_enabled ? join("", aws_elasticsearch_domain.single-public.*.arn) : join("", aws_elasticsearch_domain.single.*.arn)),
371+
var.zone_awareness_enabled ? (var.public_enabled ? format("%s/*", join("", aws_elasticsearch_domain.default-public.*.arn)) : format("%s/*", join("", aws_elasticsearch_domain.default.*.arn))) : (var.public_enabled ? format("%s/*", join("", aws_elasticsearch_domain.single-public.*.arn)) : format("%s/*", join("", aws_elasticsearch_domain.single.*.arn)))
241372
]
242373

243374
principals {
@@ -264,7 +395,7 @@ module "es_dns" {
264395
name = var.es_hostname
265396
type = var.type
266397
ttl = var.ttl
267-
values = var.zone_awareness_enabled ? join("", aws_elasticsearch_domain.default.*.endpoint) : join("", aws_elasticsearch_domain.single.*.endpoint)
398+
values = var.zone_awareness_enabled ? (var.public_enabled ? join("", aws_elasticsearch_domain.default-public.*.endpoint) : join("", aws_elasticsearch_domain.default.*.endpoint)) : (var.public_enabled ? join("", aws_elasticsearch_domain.single-public.*.endpoint) : join("", aws_elasticsearch_domain.single.*.endpoint))
268399
}
269400
#Module : ROUTE53
270401
#Description : Provides a Route53 record resource.
@@ -275,5 +406,5 @@ module "kibana_dns" {
275406
name = var.kibana_hostname
276407
type = var.type
277408
ttl = var.ttl
278-
values = var.zone_awareness_enabled ? join("", aws_elasticsearch_domain.default.*.kibana_endpoint) : join("", aws_elasticsearch_domain.single.*.kibana_endpoint)
409+
values = var.zone_awareness_enabled ? (var.public_enabled ? join("", aws_elasticsearch_domain.default-public.*.endpoint) : join("", aws_elasticsearch_domain.default.*.endpoint)) : (var.public_enabled ? join("", aws_elasticsearch_domain.single-public.*.endpoint) : join("", aws_elasticsearch_domain.single.*.endpoint))
279410
}

variables.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ variable "zone_awareness_enabled" {
104104
description = "Enable zone awareness for Elasticsearch cluster."
105105
}
106106

107+
variable "public_enabled" {
108+
type = bool
109+
default = false
110+
description = "Enable Elasticsearch cluster is public or not."
111+
}
112+
107113
variable "availability_zone_count" {
108114
type = number
109115
default = 2
@@ -214,11 +220,13 @@ variable "encryption_enabled" {
214220

215221
variable "subnet_ids" {
216222
type = list(string)
223+
default = []
217224
description = "Subnet IDs."
218225
}
219226

220227
variable "security_group_ids" {
221228
type = list(string)
229+
default = []
222230
description = "Security Group IDs."
223231
}
224232

0 commit comments

Comments
 (0)