Skip to main content

Module: elasticsearch

Terraform module to provision an Elasticsearch cluster with built-in integrations with Kibana and Logstash.

Introduction

This module will create:

  • Elasticsearch cluster with the specified node count in the provided subnets in a VPC
  • Elasticsearch domain policy that accepts a list of IAM role ARNs from which to permit management traffic to the cluster
  • Security Group to control access to the Elasticsearch domain (inputs to the Security Group are other Security Groups or CIDRs blocks to be allowed to connect to the cluster)
  • DNS hostname record for Elasticsearch cluster (if DNS Zone ID is provided)
  • DNS hostname record for Kibana (if DNS Zone ID is provided)

NOTE: To enable zone awareness to deploy Elasticsearch nodes into two different Availability Zones, you need to set zone_awareness_enabled to true and provide two different subnets in subnet_ids. If you enable zone awareness for your domain, Amazon ES places an endpoint into two subnets. The subnets must be in different Availability Zones in the same region. If you don't enable zone awareness, Amazon ES places an endpoint into only one subnet. You also need to set availability_zone_count to 1.

Usage

module "elasticsearch" {
source = "cloudposse/elasticsearch/aws"
# Cloud Posse recommends pinning every module to a specific version
# version = "x.x.x"
namespace = "eg"
stage = "dev"
name = "es"
dns_zone_id = "Z14EN2YD427LRQ"
security_groups = ["sg-XXXXXXXXX", "sg-YYYYYYYY"]
vpc_id = "vpc-XXXXXXXXX"
subnet_ids = ["subnet-XXXXXXXXX", "subnet-YYYYYYYY"]
zone_awareness_enabled = true
elasticsearch_version = "6.5"
instance_type = "t2.small.elasticsearch"
instance_count = 4
ebs_volume_size = 10
iam_role_arns = ["arn:aws:iam::XXXXXXXXX:role/ops", "arn:aws:iam::XXXXXXXXX:role/dev"]
iam_actions = ["es:ESHttpGet", "es:ESHttpPut", "es:ESHttpPost"]
encrypt_at_rest_enabled = true
kibana_subdomain_name = "kibana-es"

advanced_options = {
"rest.action.multi.allow_explicit_index" = "true"
}
}

Examples

Here is a working example of using this module:

Here are automated tests for the complete example using bats and Terratest (which tests and deploys the example on AWS):

Requirements

NameVersion
terraform>= 1.3
aws>= 3.35.0

Providers

NameVersion
aws>= 3.35.0

Modules

NameSourceVersion
domain_hostnamecloudposse/route53-cluster-hostname/aws0.12.3
kibana_hostnamecloudposse/route53-cluster-hostname/aws0.12.3
kibana_labelcloudposse/label/null0.25.0
thiscloudposse/label/null0.25.0
user_labelcloudposse/label/null0.25.0

Resources

NameType
aws_elasticsearch_domain.defaultresource
aws_elasticsearch_domain_policy.defaultresource
aws_iam_role.elasticsearch_userresource
aws_iam_service_linked_role.defaultresource
aws_opensearch_domain.defaultresource
aws_opensearch_domain_policy.defaultresource
aws_security_group.defaultresource
aws_security_group_rule.egressresource
aws_security_group_rule.ingress_cidr_blocksresource
aws_security_group_rule.ingress_security_groupsresource
aws_iam_policy_document.assume_roledata source
aws_iam_policy_document.defaultdata source

Inputs

NameDescriptionTypeDefaultRequired
additional_tag_mapAdditional key-value pairs to add to each map in tags_as_list_of_maps. Not added to tags or id.
This is for some rare cases where resources want additional configuration of tags
and therefore take a list of maps with tag key, value, and additional configuration.
map(string){}no
advanced_optionsKey-value string pairs to specify advanced configuration optionsmap(string){}no
advanced_security_options_enabledAWS Elasticsearch Kibana enchanced security plugin enabling (forces new resource)boolfalseno
advanced_security_options_internal_user_database_enabledWhether to enable or not internal Kibana user database for ELK OpenDistro security pluginboolfalseno
advanced_security_options_master_user_arnARN of IAM user who is to be mapped to be Kibana master user (applicable if advanced_security_options_internal_user_database_enabled set to false)string""no
advanced_security_options_master_user_nameMaster user username (applicable if advanced_security_options_internal_user_database_enabled set to true)string""no
advanced_security_options_master_user_passwordMaster user password (applicable if advanced_security_options_internal_user_database_enabled set to true)string""no
allowed_cidr_blocksList of CIDR blocks to be allowed to connect to the clusterlist(string)[]no
anonymous_iam_actionsList of actions to allow for the anonymous (*) IAM roles, e.g. es:ESHttpGet, es:ESHttpPut, es:ESHttpPostlist(string)[]no
attributesID element. Additional attributes (e.g. workers or cluster) to add to id,
in the order they appear in the list. New attributes are appended to the
end of the list. The elements of the list are joined by the delimiter
and treated as a single ID element.
list(string)[]no
auto_tuneThis object represents the auto_tune configuration. It contains the following filed:
- enabled - Whether to enable autotune.
- rollback_on_disable - Whether to roll back to default Auto-Tune settings when disabling Auto-Tune.
- starting_time - Date and time at which to start the Auto-Tune maintenance schedule in RFC3339 format. Time should be in the future.
- cron_schedule - A cron expression specifying the recurrence pattern for an Auto-Tune maintenance schedule.
- duration - Autotune maintanance window duration time in hours.
object({
enabled = bool
rollback_on_disable = string
starting_time = string
cron_schedule = string
duration = number
})
{
"cron_schedule": null,
"duration": null,
"enabled": false,
"rollback_on_disable": "NO_ROLLBACK",
"starting_time": null
}
no
automated_snapshot_start_hourHour at which automated snapshots are taken, in UTCnumber0no
availability_zone_countNumber of Availability Zones for the domain to use.number2no
aws_ec2_service_nameAWS EC2 Service Namelist(string)
[
"ec2.amazonaws.com"
]
no
aws_service_typeThe type of AWS service to deploy (elasticsearch or opensearch).string"elasticsearch"no
cognito_authentication_enabledWhether to enable Amazon Cognito authentication with Kibanaboolfalseno
cognito_iam_role_arnARN of the IAM role that has the AmazonESCognitoAccess policy attachedstring""no
cognito_identity_pool_idThe ID of the Cognito Identity Pool to usestring""no
cognito_user_pool_idThe ID of the Cognito User Pool to usestring""no
cold_storage_enabledEnables cold storage support.boolfalseno
contextSingle object for setting entire context at once.
See description of individual variables for details.
Leave string and numeric variables as null to use default value.
Individual variable settings (non-null) override settings in context object,
except for attributes, tags, and additional_tag_map, which are merged.
any
{
"additional_tag_map": {},
"attributes": [],
"delimiter": null,
"descriptor_formats": {},
"enabled": true,
"environment": null,
"id_length_limit": null,
"label_key_case": null,
"label_order": [],
"label_value_case": null,
"labels_as_tags": [
"unset"
],
"name": null,
"namespace": null,
"regex_replace_chars": null,
"stage": null,
"tags": {},
"tenant": null
}
no
create_elasticsearch_user_roleWhether to create an IAM role for Users/EC2 to assume to access the Elasticsearch domain. Set it to false if you already manage access through other means.booltrueno
create_iam_service_linked_roleWhether to create AWSServiceRoleForAmazonElasticsearchService service-linked role. Set it to false if you already have an ElasticSearch cluster created in the AWS account and AWSServiceRoleForAmazonElasticsearchService already exists. See https://github.com/terraform-providers/terraform-provider-aws/issues/5218 for more infobooltrueno
create_security_groupWhether to create a dedicated security group for the Elasticsearch domain. Set it to false if you already have security groups that you want to attach to the domain and specify them in the security_groups variable.booltrueno
custom_endpointFully qualified domain for custom endpoint.string""no
custom_endpoint_certificate_arnACM certificate ARN for custom endpoint.string""no
custom_endpoint_enabledWhether to enable custom endpoint for the Elasticsearch domain.boolfalseno
dedicated_master_countNumber of dedicated master nodes in the clusternumber0no
dedicated_master_enabledIndicates whether dedicated master nodes are enabled for the clusterboolfalseno
dedicated_master_typeInstance type of the dedicated master nodes in the clusterstring"t2.small.elasticsearch"no
delimiterDelimiter to be used between ID elements.
Defaults to - (hyphen). Set to "" to use no delimiter at all.
stringnullno
descriptor_formatsDescribe additional descriptors to be output in the descriptors output map.
Map of maps. Keys are names of descriptors. Values are maps of the form
{<br/> format = string<br/> labels = list(string)<br/>}
(Type is any so the map values can later be enhanced to provide additional options.)
format is a Terraform format string to be passed to the format() function.
labels is a list of labels, in order, to pass to format() function.
Label values will be normalized before being passed to format() so they will be
identical to how they appear in id.
Default is {} (descriptors output will be empty).
any{}no
dns_zone_idRoute53 DNS Zone ID to add hostname records for Elasticsearch domain and Kibanastring""no
domain_endpoint_options_enforce_httpsWhether or not to require HTTPSbooltrueno
domain_endpoint_options_tls_security_policyThe name of the TLS security policy that needs to be applied to the HTTPS endpointstring"Policy-Min-TLS-1-0-2019-07"no
domain_hostname_enabledExplicit flag to enable creating a DNS hostname for ES. If true, then var.dns_zone_id is required.boolfalseno
ebs_iopsThe baseline input/output (I/O) performance of EBS volumes attached to data nodes. Applicable only for the Provisioned IOPS EBS volume typenumber0no
ebs_throughputSpecifies the throughput (in MiB/s) of the EBS volumes attached to data nodes. Applicable only for the gp3 volume type. Valid values are between 125 and 1000.numbernullno
ebs_volume_sizeEBS volumes for data storage in GBnumber0no
ebs_volume_typeStorage type of EBS volumesstring"gp2"no
elasticsearch_subdomain_nameThe name of the subdomain for Elasticsearch in the DNS zone (_e.g._ elasticsearch, ui, ui-es, search-ui)string""no
elasticsearch_versionVersion of Elasticsearch to deploy (_e.g._ 7.4, 7.1, 6.8, 6.7, 6.5, 6.4, 6.3, 6.2, 6.0, 5.6, 5.5, 5.3, 5.1, 2.3, 1.5string"7.4"no
enabledSet to false to prevent the module from creating any resourcesboolnullno
encrypt_at_rest_enabledWhether to enable encryption at restbooltrueno
encrypt_at_rest_kms_key_idThe KMS key ID to encrypt the Elasticsearch domain with. If not specified, then it defaults to using the AWS/Elasticsearch service KMS keystring""no
environmentID element. Usually used for region e.g. 'uw2', 'us-west-2', OR role 'prod', 'staging', 'dev', 'UAT'stringnullno
iam_actionsList of actions to allow for the user IAM roles, e.g. es:ESHttpGet, es:ESHttpPut, es:ESHttpPostlist(string)[]no
iam_authorizing_role_arnsList of IAM role ARNs to permit to assume the Elasticsearch user rolelist(string)[]no
iam_role_arnsList of IAM role ARNs to permit access to the Elasticsearch domainlist(string)[]no
iam_role_max_session_durationThe maximum session duration (in seconds) for the user role. Can have a value from 1 hour to 12 hoursnumber3600no
iam_role_permissions_boundaryThe ARN of the permissions boundary policy which will be attached to the Elasticsearch user rolestringnullno
id_length_limitLimit id to this many characters (minimum 6).
Set to 0 for unlimited length.
Set to null for keep the existing setting, which defaults to 0.
Does not affect id_full.
numbernullno
ingress_port_range_endEnd number for allowed port range. (e.g. 443)number65535no
ingress_port_range_startStart number for allowed port range. (e.g. 443)number0no
instance_countNumber of data nodes in the clusternumber4no
instance_typeElasticsearch instance type for data nodes in the clusterstring"t2.small.elasticsearch"no
kibana_hostname_enabledExplicit flag to enable creating a DNS hostname for Kibana. If true, then var.dns_zone_id is required.boolfalseno
kibana_subdomain_nameThe name of the subdomain for Kibana in the DNS zone (_e.g._ kibana, ui, ui-es, search-ui, kibana.elasticsearch)string""no
label_key_caseControls the letter case of the tags keys (label names) for tags generated by this module.
Does not affect keys of tags passed in via the tags input.
Possible values: lower, title, upper.
Default value: title.
stringnullno
label_orderThe order in which the labels (ID elements) appear in the id.
Defaults to ["namespace", "environment", "stage", "name", "attributes"].
You can omit any of the 6 labels ("tenant" is the 6th), but at least one must be present.
list(string)nullno
label_value_caseControls the letter case of ID elements (labels) as included in id,
set as tag values, and output by this module individually.
Does not affect values of tags passed in via the tags input.
Possible values: lower, title, upper and none (no transformation).
Set this to title and set delimiter to "" to yield Pascal Case IDs.
Default value: lower.
stringnullno
labels_as_tagsSet of labels (ID elements) to include as tags in the tags output.
Default is to include all labels.
Tags with empty values will not be included in the tags output.
Set to [] to suppress all generated tags.
Notes:
The value of the name tag, if included, will be the id, not the name.
Unlike other null-label inputs, the initial setting of labels_as_tags cannot be
changed in later chained modules. Attempts to change it will be silently ignored.
set(string)
[
"default"
]
no
log_publishing_application_cloudwatch_log_group_arnARN of the CloudWatch log group to which log for ES_APPLICATION_LOGS needs to be publishedstring""no
log_publishing_application_enabledSpecifies whether log publishing option for ES_APPLICATION_LOGS is enabled or notboolfalseno
log_publishing_audit_cloudwatch_log_group_arnARN of the CloudWatch log group to which log for AUDIT_LOGS needs to be publishedstring""no
log_publishing_audit_enabledSpecifies whether log publishing option for AUDIT_LOGS is enabled or notboolfalseno
log_publishing_index_cloudwatch_log_group_arnARN of the CloudWatch log group to which log for INDEX_SLOW_LOGS needs to be publishedstring""no
log_publishing_index_enabledSpecifies whether log publishing option for INDEX_SLOW_LOGS is enabled or notboolfalseno
log_publishing_search_cloudwatch_log_group_arnARN of the CloudWatch log group to which log for SEARCH_SLOW_LOGS needs to be publishedstring""no
log_publishing_search_enabledSpecifies whether log publishing option for SEARCH_SLOW_LOGS is enabled or notboolfalseno
nameID element. Usually the component or solution name, e.g. 'app' or 'jenkins'.
This is the only ID element not also included as a tag.
The "name" tag is set to the full id string. There is no tag with the value of the name input.
stringnullno
namespaceID element. Usually an abbreviation of your organization name, e.g. 'eg' or 'cp', to help ensure generated IDs are globally uniquestringnullno
node_to_node_encryption_enabledWhether to enable node-to-node encryptionboolfalseno
regex_replace_charsTerraform regular expression (regex) string.
Characters matching the regex will be removed from the ID elements.
If not set, "/[^a-zA-Z0-9-]/" is used to remove all characters other than hyphens, letters and digits.
stringnullno
security_groupsList of security group IDs to be allowed to connect to the cluster or the security group IDs to apply to the cluster when the create_security_group variable is set to false.list(string)[]no
stageID element. Usually used to indicate role, e.g. 'prod', 'staging', 'source', 'build', 'test', 'deploy', 'release'stringnullno
subnet_idsVPC Subnet IDslist(string)[]no
tagsAdditional tags (e.g. {'BusinessUnit': 'XYZ'}).
Neither the tag keys nor the tag values will be modified by this module.
map(string){}no
tenantID element _(Rarely used, not included by default)_. A customer identifier, indicating who this instance of a resource is forstringnullno
vpc_enabledSet to false if ES should be deployed outside of VPC.booltrueno
vpc_idVPC IDstringnullno
warm_countNumber of UltraWarm nodesnumber2no
warm_enabledWhether AWS UltraWarm is enabledboolfalseno
warm_typeType of UltraWarm nodesstring"ultrawarm1.medium.elasticsearch"no
zone_awareness_enabledEnable zone awareness for Elasticsearch clusterbooltrueno

Outputs

NameDescription
domain_arnARN of the Elasticsearch domain
domain_endpointDomain-specific endpoint used to submit index, search, and data upload requests
domain_hostnameElasticsearch domain hostname to submit index, search, and data upload requests
domain_idUnique identifier for the Elasticsearch domain
domain_nameName of the Elasticsearch domain
elasticsearch_user_iam_role_arnThe ARN of the IAM role to allow access to Elasticsearch cluster
elasticsearch_user_iam_role_nameThe name of the IAM role to allow access to Elasticsearch cluster
kibana_endpointDomain-specific endpoint for Kibana without https scheme
kibana_hostnameKibana hostname
security_group_idSecurity Group ID to control access to the Elasticsearch domain