Elasticsearch How to Install OpenSearch on EC2 Using Terraform

Average Read Time

2 Mins

Elasticsearch How to Install OpenSearch on EC2 Using Terraform

Opster Team

October 2021

Average Read Time

2 Mins


In addition to reading this guide, we recommend you run the Elasticsearch Health Check-Up. It will detect issues and improve your Elasticsearch performance by analyzing your shard sizes, threadpools, memory, snapshots, disk watermarks and more.

The Elasticsearch Check-Up is free and requires no installation.

OpenSearch was created as a community-driven, open source fork of Elasticsearch and Kibana. OpenSearch includes a search engine daemon and dashboards for visualization and user interface.  

Opster is committed to the continuous improvement of open source technologies and sees the need for new tools for running OpenSearch. In this guide, we will be sharing a new Terraform module we built for installing OpenSearch clusters in AWS.

What you need for installing OpenSearch on EC2

The new Terraform module will deploy by default 5 EC2 instances, 3 EBS, and 5 route-53 records. The EC2 instances will host 3 data nodes, 1 master node and 1 OpenSearch dashboard.

You can choose whether to deploy the cluster in one of your existing VPCs or create a new VPC to deploy the cluster in. 

Note that in order for the module to succeed, you must have a route-53 resource that connects to your VPC. This is needed for the node discovery.

These are the variables you will need to set and update in order to deploy the cluster in the root folder on  main.tf file:

  cluster_name = "opensearch-cluster"
  key_name = 
  create_vpc = 
  vpc_id = 
  subnet_id = 
  route53_zone = 
  route53_domain = 
  Path_to_data = 

If you want you can also change more variables as you wish in modules/opensearch/variables but  we recommend keeping some of these variables at their default settings, including:

  • Ami = Centos7, should be kept that way because the installation script adjusted to this OS.
  • Instance_type = if you want to change it, please keep the ec2’s with at least 8 GB ram.

Here you can also change the architecture of your environment and add more nodes, just keep in mind that you will always need at least 1 data node, 1 master and 1 dashboard. If you choose to add more nodes, do not forget to add those hosts to the OpenSearch conf file on source/conf_setup (see more details on README.md file). 

The variables we recommend changing are:

  • Key_name
  • Create_vpc
  • Vpc_id
  • Subnet_id
  • Reoute53_zone
  • Route53_domain

How to deploy your new OpenSearch cluster

After setting all the variables, run the following 3 commands in the root main.tf directory to deploy the cluster:

   terraform init
   terraform plan
   terraform apply

Follow the execution output and wait a few minutes for the cluster to appear. This is the the message you’ll see confirming that the cluster has been created:

Apply complete! Resources: 10 added, 0 changed, 0 destroyed.

It will take more or less 10 minutes for the cluster to finish its initialization process & bootstrap checks and become available for use.

To check that the cluster is up, running, and available, you can run the following command and wait for a 200-ok response.

curl -XGET https://master-opensearch.domain.com:9200 -u 'admin:admin' --insecure

That’s it! Your cluster is up and running. In order to access OpenSearch Dashboards you can go in your browser to dashboard-opensearch..com:5601/ and connect with admin:admin.

If you have any questions, you can follow the Terraform module in the github repo – see here. Feel free to open a ticket or a Pull Request if you want to contribute, and stay tuned – the Opster team is working on some very cool and valuable OpenSearch additions, coming soon! 



Run the Check-Up to get a customized report like this:

Analyze your cluster