Skip to content

Commit dcddc1c

Browse files
committed
Upgrade the TF module minimal to Terraform 0.12+
1 parent 197fa62 commit dcddc1c

File tree

9 files changed

+70
-31
lines changed

9 files changed

+70
-31
lines changed

minimal/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Terraform Elasticsearch Single Node on AWS
2+
3+
Example of the creation of an AWS Elasticsearch single node with Terraform
4+
5+
## Includes
6+
7+
- Create an AWS Elasticsearch Service instance (managed by AWS)
8+
- Deploy the Elasticsearch instance under your default VPC
9+
- Encryption with a KMS custom key (let you manage the usage of the KMS key)
10+
- Accessible only from your office/home public IP
11+
12+
## Improvements
13+
14+
This project is just a minimal example of how to deploy an AWS Elasticsearch service instance with a single node with the minimum of security.
15+
16+
This Terraform module can also be improved by adding this changes:
17+
18+
- Support for multiple environments (distinct name and tags between environment)
19+
- Support for Route 53 (by adding an alias to an existing Route 53 zone)
20+
21+
```bash
22+
module "es-single-node" {
23+
source = "git::https://github.com/timoa/terraform-elastic-single-node/minimal"
24+
25+
name = "es-single-node-example"
26+
27+
# Need to be greater than t2 since it doesn't support encryption
28+
instance_type = "m4.large.elasticsearch"
29+
30+
}
31+
```

minimal/main.tf

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,25 @@ module "security" {
1717
source = "./modules/security"
1818

1919
# Tags
20-
tags = "${var.tags}"
20+
tags = var.tags
2121
}
2222

2323
module "elasticsearch" {
2424
source = "./modules/elasticsearch"
2525

2626
# Global
27-
aws_region = "${var.aws_region}"
27+
aws_region = var.aws_region
2828

2929
# Security
30-
my_public_ip = "${var.my_public_ip}"
31-
encryption_kms_key_id = "${module.security.elasticsearch_kms_key_id}"
30+
my_public_ip = var.my_public_ip
31+
encryption_kms_key_id = module.security.elasticsearch_kms_key_id
3232

3333
# Elasticsearch
34-
domain_name = "${var.domain_name}"
35-
elasticsearch_version = "${var.elasticsearch_version}"
36-
instance_type = "${var.instance_type}"
37-
volume_size = "${var.volume_size}"
34+
domain_name = var.domain_name
35+
elasticsearch_version = var.elasticsearch_version
36+
instance_type = var.instance_type
37+
volume_size = var.volume_size
3838

3939
# Tags
40-
tags = "${var.tags}"
40+
tags = var.tags
4141
}

minimal/modules/elasticsearch/main.tf

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@ data "aws_caller_identity" "current" {}
55

66
resource "aws_elasticsearch_domain" "elasticsearch" {
77
# Name of the Elasticsearch cluster (domain)
8-
domain_name = "${var.domain_name}"
8+
domain_name = var.domain_name
99

1010
# Elasticsearch version (last supported by AWS is 6.3)
11-
elasticsearch_version = "${var.elasticsearch_version}"
11+
elasticsearch_version = var.elasticsearch_version
1212

1313
# Encryption of the Elasticsearch instance volume with a KMS CMK
1414
encrypt_at_rest {
1515
enabled = "true"
16-
kms_key_id = "${var.encryption_kms_key_id}"
16+
kms_key_id = var.encryption_kms_key_id
1717
}
1818

1919
cluster_config {
2020
# Instance type of the data node in the cluster
21-
instance_type = "${var.instance_type}"
21+
instance_type = var.instance_type
2222

2323
# Number of instances in the cluster (single node = 1)
2424
instance_count = "1"
@@ -53,15 +53,15 @@ resource "aws_elasticsearch_domain" "elasticsearch" {
5353
}
5454
POLICY
5555

56-
advanced_options {
56+
advanced_options = {
5757
"rest.action.multi.allow_explicit_index" = "true"
5858
"indices.query.bool.max_clause_count" = "1024"
5959
}
6060

6161
ebs_options {
6262
ebs_enabled = true
6363
volume_type = "gp2"
64-
volume_size = "${var.volume_size}"
64+
volume_size = var.volume_size
6565
}
6666

6767
snapshot_options {
@@ -70,8 +70,8 @@ resource "aws_elasticsearch_domain" "elasticsearch" {
7070
}
7171

7272
# Tags
73-
tags = "${merge(var.tags, map(
73+
tags = merge(var.tags, map(
7474
"Name", "elasticsearch-es",
75-
"Domain", "${var.domain_name}"
76-
))}"
75+
"Domain", var.domain_name
76+
))
7777
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
output "elasticsearch_endpoint" {
22
description = "Domain-specific endpoint used to submit index, search, and data upload requests"
3-
value = "${aws_elasticsearch_domain.elasticsearch.endpoint}"
3+
value = aws_elasticsearch_domain.elasticsearch.endpoint
44
}
55

66
output "elasticsearch_arn" {
77
description = "Amazon Resource Name (ARN) of the domain"
8-
value = "${aws_elasticsearch_domain.elasticsearch.arn}"
8+
value = aws_elasticsearch_domain.elasticsearch.arn
99
}
1010

1111
output "elasticsearch_domain_id" {
1212
description = "Unique identifier for the domain"
13-
value = "${aws_elasticsearch_domain.elasticsearch.domain_id}"
13+
value = aws_elasticsearch_domain.elasticsearch.domain_id
1414
}
1515

1616
output "elasticsearch_kibana_endpoint" {
1717
description = "Domain-specific endpoint for kibana without https scheme"
18-
value = "${aws_elasticsearch_domain.elasticsearch.kibana_endpoint}"
18+
value = aws_elasticsearch_domain.elasticsearch.kibana_endpoint
1919
}

minimal/modules/security/main.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ resource "aws_kms_key" "elasticsearch_kms_key" {
22
description = "KMS key used to encrypt the Elasticsearch volume"
33

44
# Tags
5-
tags = "${merge(var.tags, map(
5+
tags = merge(var.tags, map(
66
"Name", "elasticsearch-kms"
7-
))}"
7+
))
88
}
99

1010
resource "aws_kms_alias" "key" {
1111
name = "alias/elasticsearch-kms"
12-
target_key_id = "${aws_kms_key.elasticsearch_kms_key.key_id}"
12+
target_key_id = aws_kms_key.elasticsearch_kms_key.key_id
1313
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
output "elasticsearch_kms_key_id" {
22
description = "Elasticsearch KMS Key ID"
3-
value = "${aws_kms_key.elasticsearch_kms_key.key_id}"
3+
value = aws_kms_key.elasticsearch_kms_key.key_id
44
}

minimal/outputs.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
output "elasticsearch_endpoint" {
22
description = "Elasticsearch public endpoint"
3-
value = "${module.elasticsearch.elasticsearch_endpoint}"
3+
value = module.elasticsearch.elasticsearch_endpoint
44
}
55

66
output "elasticsearch_kibana_endpoint" {
77
description = "Elasticsearch Kibana public endpoint"
8-
value = "${module.elasticsearch.elasticsearch_kibana_endpoint}"
8+
value = module.elasticsearch.elasticsearch_kibana_endpoint
99
}

minimal/provider.tf

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
provider "aws" {
2-
region = "${var.aws_region}"
3-
version = "~> 1.55"
2+
region = var.aws_region
3+
version = "~> 2.7"
4+
}
5+
6+
provider "template" {
7+
version = "~> 2.1"
8+
}
9+
10+
provider "null" {
11+
version = "~> 2.1"
412
}

minimal/variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ variable "domain_name" {
2222
}
2323

2424
variable "elasticsearch_version" {
25-
default = "6.3"
25+
default = "6.8"
2626
description = "Elastic Search Service cluster version number."
2727
type = "string"
2828
}

0 commit comments

Comments
 (0)