Create aws elasticsearch terraform code example
Example 1: terraform create elastic search instance
resource "aws_elasticsearch_domain" "es" {
domain_name = "${var.es_domain}"
elasticsearch_version = "6.3"
cluster_config {
instance_type = "r4.large.elasticsearch"
}
vpc_options {
subnet_ids = "${var.es_subnets}"
security_group_ids = [
"${aws_security_group.es_sg.id}"
]
}
ebs_options {
ebs_enabled = true
volume_size = 10
}
access_policies = <<CONFIG
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "es:*",
"Principal": "*",
"Effect": "Allow",
"Resource": "arn:aws:es:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:domain/${var.es_domain}/*"
}
]
}
CONFIG
snapshot_options {
automated_snapshot_start_hour = 23
}
tags {
Domain = "${var.es_domain}"
}
}
Example 2: terraform create elastic search instance
resource "aws_security_group" "es_sg" {
name = "${var.es_domain}-sg"
description = "Allow inbound traffic to ElasticSearch from VPC CIDR"
vpc_id = "${var.vpc}"
ingress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = [
"${var.vpc_cidr}"
]
}
}