Skip to content

Commit

Permalink
Add single node cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita Dugar committed Sep 27, 2019
1 parent 7a3ea9f commit 8421ce5
Show file tree
Hide file tree
Showing 11 changed files with 272 additions and 52 deletions.
68 changes: 46 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,32 +68,56 @@ This module has a few dependencies:
**IMPORTANT:** Since the `master` branch used in `source` varies based on new modifications, we suggest that you use the release versions [here](https://github.com/clouddrove/terraform-aws-elasticsearch/releases).


### Simple Example
Here is an example of how you can use this module in your inventory structure:
Here are examples of how you can use this module in your inventory structure:
### Single Node
```hcl
module "elasticsearch" {
source = "git::https://github.com/clouddrove/terraform-aws-elasticsearch.git?ref=tags/0.12.0"
name = "es"
application = "clouddrove"
environment = "test"
label_order = ["environment", "name", "application"]
domain_name = "clouddrove"
source = "git::https://github.com/clouddrove/terraform-aws-elasticsearch.git?ref=tags/0.12.0"
name = "es"
application = "clouddrove"
environment = "test"
label_order = ["environment", "name", "application"]
domain_name = "clouddrove"
enable_iam_service_linked_role = true
security_group_ids = ["sg-xxxxxxxxxxx"]
subnet_ids = ["subnet-xxxxxxxxxxx"]
zone_awareness_enabled = true
elasticsearch_version = "6.5"
instance_type = "t2.small.elasticsearch"
instance_count = 4
iam_actions = ["es:ESHttpGet", "es:ESHttpPut", "es:ESHttpPost"]
volume_size = 10
volume_type = "gp2"
advanced_options = {
"rest.action.multi.allow_explicit_index" = "true"
}
security_group_ids = ["sg-xxxxxxxxxxxx"]
subnet_ids = ["subnet-xxxxxxxxxxxx"]
elasticsearch_version = "7.1"
instance_type = "t2.small.elasticsearch"
instance_count = 1
iam_actions = ["es:ESHttpGet", "es:ESHttpPut", "es:ESHttpPost"]
volume_size = 30
volume_type = "gp2"
advanced_options = {
"rest.action.multi.allow_explicit_index" = "true"
}
}
```
Note: There are some type of instances which not support encryption and EBS option, Please read about this (here)[https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/aes-supported-instance-types.html]
### Multi Node
```hcl
module "elasticsearch" {
source = "git::https://github.com/clouddrove/terraform-aws-elasticsearch.git?ref=tags/0.12.0"
name = "es"
application = "clouddrove"
environment = "test"
label_order = ["environment", "name", "application"]
domain_name = "clouddrove"
enable_iam_service_linked_role = true
security_group_ids = ["sg-xxxxxxxxxxxx"]
subnet_ids = ["subnet-xxxxxxxxxxxx"]
zone_awareness_enabled = true
availability_zone_count = 2
elasticsearch_version = "7.1"
instance_type = "t2.small.elasticsearch"
instance_count = 1
iam_actions = ["es:ESHttpGet", "es:ESHttpPut", "es:ESHttpPost"]
volume_size = 30
volume_type = "gp2"
advanced_options = {
"rest.action.multi.allow_explicit_index" = "true"
}
}
```
Note: There are some type of instances which not support encryption and EBS option, Please read about this (here)[https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/aes-supported-instance-types.html]. Also, there are some limitation for instance type, Please read (here)[https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/aes-limits.html]



Expand Down Expand Up @@ -140,7 +164,7 @@ Note: There are some type of instances which not support encryption and EBS opti
| tags | Additional tags (e.g. map(`BusinessUnit`,`XYZ`). | map | `<map>` | no |
| volume_size | EBS volumes for data storage in GB. | number | `0` | no |
| volume_type | Storage type of EBS volumes. | string | `gp2` | no |
| zone_awareness_enabled | Enable zone awareness for Elasticsearch cluster. | bool | `true` | no |
| zone_awareness_enabled | Enable zone awareness for Elasticsearch cluster. | bool | `false` | no |

## Outputs

Expand Down
66 changes: 45 additions & 21 deletions README.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,53 @@ include:

# How to use this project
usage : |-
### Simple Example
Here is an example of how you can use this module in your inventory structure:
Here are examples of how you can use this module in your inventory structure:
### Single Node
```hcl
module "elasticsearch" {
source = "git::https://github.com/clouddrove/terraform-aws-elasticsearch.git?ref=tags/0.12.0"
name = "es"
application = "clouddrove"
environment = "test"
label_order = ["environment", "name", "application"]
domain_name = "clouddrove"
source = "git::https://github.com/clouddrove/terraform-aws-elasticsearch.git?ref=tags/0.12.0"
name = "es"
application = "clouddrove"
environment = "test"
label_order = ["environment", "name", "application"]
domain_name = "clouddrove"
enable_iam_service_linked_role = true
security_group_ids = ["sg-xxxxxxxxxxx"]
subnet_ids = ["subnet-xxxxxxxxxxx"]
zone_awareness_enabled = true
elasticsearch_version = "6.5"
instance_type = "t2.small.elasticsearch"
instance_count = 4
iam_actions = ["es:ESHttpGet", "es:ESHttpPut", "es:ESHttpPost"]
volume_size = 10
volume_type = "gp2"
advanced_options = {
"rest.action.multi.allow_explicit_index" = "true"
}
security_group_ids = ["sg-xxxxxxxxxxxx"]
subnet_ids = ["subnet-xxxxxxxxxxxx"]
elasticsearch_version = "7.1"
instance_type = "t2.small.elasticsearch"
instance_count = 1
iam_actions = ["es:ESHttpGet", "es:ESHttpPut", "es:ESHttpPost"]
volume_size = 30
volume_type = "gp2"
advanced_options = {
"rest.action.multi.allow_explicit_index" = "true"
}
}
```
Note: There are some type of instances which not support encryption and EBS option, Please read about this (here)[https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/aes-supported-instance-types.html]
### Multi Node
```hcl
module "elasticsearch" {
source = "git::https://github.com/clouddrove/terraform-aws-elasticsearch.git?ref=tags/0.12.0"
name = "es"
application = "clouddrove"
environment = "test"
label_order = ["environment", "name", "application"]
domain_name = "clouddrove"
enable_iam_service_linked_role = true
security_group_ids = ["sg-xxxxxxxxxxxx"]
subnet_ids = ["subnet-xxxxxxxxxxxx"]
zone_awareness_enabled = true
availability_zone_count = 2
elasticsearch_version = "7.1"
instance_type = "t2.small.elasticsearch"
instance_count = 1
iam_actions = ["es:ESHttpGet", "es:ESHttpPut", "es:ESHttpPost"]
volume_size = 30
volume_type = "gp2"
advanced_options = {
"rest.action.multi.allow_explicit_index" = "true"
}
}
```
Note: There are some type of instances which not support encryption and EBS option, Please read about this (here)[https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/aes-supported-instance-types.html]. Also, there are some limitation for instance type, Please read (here)[https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/aes-limits.html]
7 changes: 4 additions & 3 deletions _example/example.tf → _example/multi-node/example.tf
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@ module "elasticsearch" {
security_group_ids = [module.security_group.security_group_ids]
subnet_ids = tolist(module.public_subnets.public_subnet_id)
zone_awareness_enabled = true
elasticsearch_version = "6.5"
availability_zone_count = 2
elasticsearch_version = "7.1"
instance_type = "t2.small.elasticsearch"
instance_count = 4
instance_count = 1
iam_actions = ["es:ESHttpGet", "es:ESHttpPut", "es:ESHttpPost"]
volume_size = 10
volume_size = 30
volume_type = "gp2"
advanced_options = {
"rest.action.multi.allow_explicit_index" = "true"
Expand Down
File renamed without changes.
63 changes: 63 additions & 0 deletions _example/single-node/example.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
provider "aws" {
region = "eu-west-1"
}

module "vpc" {
source = "git::https://github.com/clouddrove/terraform-aws-vpc.git?ref=tags/0.12.1"

name = "vpc"
application = "clouddrove"
environment = "test"
label_order = ["environment", "name", "application"]

cidr_block = "172.16.0.0/16"
}

module "public_subnets" {
source = "git::https://github.com/clouddrove/terraform-aws-subnet.git?ref=tags/0.12.1"

name = "public-subnet"
application = "clouddrove"
environment = "test"
label_order = ["environment", "name", "application"]

availability_zones = ["eu-west-1c"]
vpc_id = module.vpc.vpc_id
cidr_block = module.vpc.vpc_cidr_block
type = "public"
igw_id = module.vpc.igw_id
}

module "security_group" {
source = "git::https://github.com/clouddrove/terraform-aws-security-group.git?ref=tags/0.12.1"

name = "ingress_security_groups"
application = "clouddrove"
environment = "test"
label_order = ["environment", "name", "application"]

vpc_id = module.vpc.vpc_id
allowed_ip = ["0.0.0.0/0"]
allowed_ports = [80, 443, 9200]
}

module "elasticsearch" {
source = "git::https://github.com/clouddrove/terraform-aws-elasticsearch.git?ref=tags/0.12.0"
name = "es"
application = "clouddrove"
environment = "test"
label_order = ["environment", "name", "application"]
domain_name = "clouddrove"
enable_iam_service_linked_role = true
security_group_ids = [module.security_group.security_group_ids]
subnet_ids = tolist(module.public_subnets.public_subnet_id)
elasticsearch_version = "7.1"
instance_type = "t2.small.elasticsearch"
instance_count = 1
iam_actions = ["es:ESHttpGet", "es:ESHttpPut", "es:ESHttpPost"]
volume_size = 30
volume_type = "gp2"
advanced_options = {
"rest.action.multi.allow_explicit_index" = "true"
}
}
9 changes: 9 additions & 0 deletions _example/single-node/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
output "arn" {
value = module.elasticsearch.domain_arn
description = "ARN of the Elasticsearch domain."
}

output "tags" {
value = module.elasticsearch.tags
description = "A mapping of tags to assign to the resource."
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func Test(t *testing.T) {

terraformOptions := &terraform.Options{
// Source path of Terraform directory.
TerraformDir: "../_example",
TerraformDir: "../../_example/multi-node",
Upgrade: true,
}

Expand Down
34 changes: 34 additions & 0 deletions _test/single-node/elasticsearch_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Managed By : CloudDrove
// Description : This Terratest is used to test the Terraform Elasticsearch module.
// Copyright @ CloudDrove. All Right Reserved.
package test

import (
"testing"
"github.com/gruntwork-io/terratest/modules/terraform"
"github.com/stretchr/testify/assert"
)

func Test(t *testing.T) {
t.Parallel()

terraformOptions := &terraform.Options{
// Source path of Terraform directory.
TerraformDir: "../../_example/single-node",
Upgrade: true,
}

// This will run 'terraform init' and 'terraform application' and will fail the test if any errors occur
terraform.InitAndApply(t, terraformOptions)

// To clean up any resources that have been created, run 'terraform destroy' towards the end of the test
defer terraform.Destroy(t, terraformOptions)

// To get the value of an output variable, run 'terraform output'
Tags := terraform.OutputMap(t, terraformOptions, "tags")
Arn := terraform.Output(t, terraformOptions, "arn")

// Check that we get back the outputs that we expect
assert.Equal(t, "clouddrove", Tags["Name"])
assert.Contains(t, Arn, "arn:aws:es")
}
71 changes: 68 additions & 3 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ data "aws_iam_policy_document" "assume_role" {
#Module : Elasticsearch
#Description : Terraform module to create Elasticsearch resource on AWS.
resource "aws_elasticsearch_domain" "default" {
count = var.enabled ? 1 : 0
count = var.enabled && var.zone_awareness_enabled ? 1 : 0
domain_name = var.domain_name
elasticsearch_version = var.elasticsearch_version

Expand Down Expand Up @@ -125,6 +125,71 @@ resource "aws_elasticsearch_domain" "default" {
depends_on = [aws_iam_service_linked_role.default]
}

#Module : Elasticsearch
#Description : Terraform module to create Elasticsearch resource on AWS.
resource "aws_elasticsearch_domain" "single" {
count = var.enabled && var.zone_awareness_enabled == false ? 1 : 0
domain_name = var.domain_name
elasticsearch_version = var.elasticsearch_version

advanced_options = var.advanced_options

ebs_options {
ebs_enabled = var.volume_size > 0 ? true : false
volume_size = var.volume_size
volume_type = var.volume_type
iops = var.iops
}

encrypt_at_rest {
enabled = false
kms_key_id = var.kms_key_id
}

cluster_config {
instance_count = var.instance_count
instance_type = var.instance_type
dedicated_master_enabled = var.dedicated_master_enabled
dedicated_master_count = var.dedicated_master_count
dedicated_master_type = var.dedicated_master_type
}

node_to_node_encryption {
enabled = var.encryption_enabled
}

vpc_options {
security_group_ids = var.security_group_ids
subnet_ids = var.subnet_ids
}

snapshot_options {
automated_snapshot_start_hour = var.automated_snapshot_start_hour
}

log_publishing_options {
enabled = var.log_publishing_index_enabled
log_type = "INDEX_SLOW_LOGS"
cloudwatch_log_group_arn = var.log_publishing_index_cloudwatch_log_group_arn
}

log_publishing_options {
enabled = var.log_publishing_search_enabled
log_type = "SEARCH_SLOW_LOGS"
cloudwatch_log_group_arn = var.log_publishing_search_cloudwatch_log_group_arn
}

log_publishing_options {
enabled = var.log_publishing_application_enabled
log_type = "ES_APPLICATION_LOGS"
cloudwatch_log_group_arn = var.log_publishing_application_cloudwatch_log_group_arn
}

tags = module.labels.tags

depends_on = [aws_iam_service_linked_role.default]
}

#Module : Elasticsearch Role Policy
#Description : Terraform module to create Elasticsearch resource on AWS.
data "aws_iam_policy_document" "default" {
Expand All @@ -134,8 +199,8 @@ data "aws_iam_policy_document" "default" {
actions = distinct(compact(var.iam_actions))

resources = [
join("", aws_elasticsearch_domain.default.*.arn),
format("%s/*", join("", aws_elasticsearch_domain.default.*.arn))
var.zone_awareness_enabled ? join("", aws_elasticsearch_domain.default.*.arn) : join("", aws_elasticsearch_domain.single.*.arn),
var.zone_awareness_enabled ? format("%s/*", join("", aws_elasticsearch_domain.default.*.arn)) : format("%s/*", join("", aws_elasticsearch_domain.single.*.arn))
]

principals {
Expand Down
Loading

0 comments on commit 8421ce5

Please sign in to comment.