Creating an OpenSearch Cluster using Terraform
This document serves as a supplement to the existing Terraform documentation for OpenSearch, with the aim of offering an in-depth understanding of specific schema blocks and providing additional examples for creating an OpenSearch cluster using these blocks.
To understand how OpenSearch node roles behave, refer to the OpenSearch documentation on node roles.
Table of Contents
Terminology
- “Cluster manager eligible node”: nodes that contain the “cluster_manager” (previously known as “master”) role and can contain other roles, such as “data” or “ingest”.
- “Dedicated cluster manager nodes”: nodes that solely contain the “cluster_manager” (previously known as “master”) role and excludes other roles such as “data” or “ingest”.
- “Data + ingest nodes”: nodes that contain the roles “data” and “ingest” while excluding other roles such as “cluster_manager”.
- “Dedicated data nodes”: nodes that exclusively contain the “data” role, without taking on other roles such as “cluster_manager” or “ingest”.
- “Dedicated ingest nodes”: nodes that exclusively have the “ingest” role, without other roles such as “data” or “cluster_manager”.
Schema blocks in the OpenSearch resource
- “cluster_manager_nodes” block: This is a mandatory nested block required regardless of whether the OpenSearch cluster is provisioned with or without dedicated cluster manager nodes.
- a. When the “dedicated_manager” field within this block is set to false, an OpenSearch cluster featuring cluster manager eligible nodes will be provisioned.
- b. When the “dedicated_manager” field in this block is set to true, an OpenSearch cluster with dedicated cluster manager nodes will be provisioned. This setting necessitates specifying the “data_nodes” block, as provisioning a cluster solely with cluster manager nodes is not permissible.
- “data_nodes” block: This is an optional nested block to assist with provisioning of data nodes. However, it becomes mandatory when provisioning the OpenSearch cluster with dedicated cluster manager nodes
- “ingest_nodes” block: This is an optional nested block that facilitates the provisioning of dedicated ingest nodes
An overview of how the cluster will be provisioned when using the various schema blocks mentioned above is as follows:
Scenario |
dedicated_manager flag | data_nodes defined?* |
ingest_nodes defined?* |
Result |
1 | ✅ | ✅ |
✅ |
3 x dedicated cluster manager nodes with the role – “cluster_manager” + 3 x dedicated data nodes with the role – “data” + 3 x dedicated ingest nodes with the role – “ingest” |
2 |
❌ | ❌ |
❌ |
3 x cluster manager eligible nodes with roles – “cluster_manager”, “data”, “ingest” |
3 |
❌ | ✅ |
❌ |
3 x cluster manager eligible nodes with roles – “cluster_manager”, “data”, “ingest” + 3 x data + ingest nodes with roles – “data”, “ingest” |
4 |
❌ | ❌ |
✅ |
3 x cluster manager eligible nodes with roles – “cluster_manager” and “data” + 3 x dedicated ingest nodes with the role – “ingest” |
5 |
✅ | ✅ |
❌ |
3 x dedicated cluster manager nodes with the role – “cluster_manager” + 3 x data + ingest nodes with roles – “data”, “ingest” |
6 |
❌ | ✅ |
✅ |
3 x cluster manager eligible nodes with roles – “cluster_manager” and “data” + 3 x dedicated data nodes with the role – “data” + 3 x dedicated ingest nodes with the role – “ingest” |
7 |
✅ | ❌ |
❌ |
Invalid combination, due to missing “data_nodes” block when “dedicated_manager = true” |
8 |
✅ | ❌ |
✅ |
Invalid combination, due to missing “data_nodes” block when “dedicated_manager = true” |
* Assumes “node_count = 3”
Examples
The following are set examples covering common use-cases:
Scenario 1: Provision an OpenSearch cluster with 3 dedicated manager nodes, 3 dedicated data nodes and 3 dedicated ingest nodes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
resource "instaclustr_opensearch_cluster_v2" "my_test_cluster_example" { name = "my_test_cluster_example" opensearch_major_version = "2" sla_tier = "NON_PRODUCTION" pci_compliance_mode = false load_balancer = false private_network_cluster = false data_centre { cloud_provider = "AWS_VPC" name = "AWS_VPC_US_EAST_1" network = "10.0.0.0/16" number_of_racks = 3 private_link = false region = "US_EAST_1" } # Note: the "cluster_manager_nodes" block is a required block cluster_manager_nodes { dedicated_manager = true node_size = "SRH-DM-DEV-t4g.small-5" } # Note: the "data_nodes" block becomes mandatory because dedicated_manager = true data_nodes { node_count = 3 node_size = "SRH-DEV-t4g.small-5" } # Note: the "ingest_nodes" block is an optional block in this example ingest_nodes { node_count = 3 node_size = "SRH-DI-DEV-t4g.small-5" } } |
This example provisions a 9-node cluster, with 3 dedicated manager nodes assigned with the role of “cluster_manager”, and 3 dedicated data nodes with the role “data”, and 3 dedicated ingest nodes with the role of “ingest”.
Scenario 2: Provision an OpenSearch cluster with 3 cluster manager eligible nodes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
resource "instaclustr_opensearch_cluster_v2" "my_test_cluster_example" { name = "my_test_cluster_example" opensearch_major_version = "2" sla_tier = "NON_PRODUCTION" pci_compliance_mode = false load_balancer = false private_network_cluster = false data_centre { cloud_provider = "AWS_VPC" name = "AWS_VPC_US_EAST_1" network = "10.0.0.0/16" number_of_racks = 3 private_link = false region = "US_EAST_1" } # Note: the "cluster_manager_nodes" block is a required block cluster_manager_nodes { dedicated_manager = false node_size = "SRH-DEV-t4g.small-5" } } |
This example provisions a 3-node cluster, with each node assigned with the roles of “data”, “ingest” and “cluster_manager”. These nodes are known as the cluster manager eligible nodes.
Scenario 3: Provision an OpenSearch cluster with 3 cluster manager eligible nodes and 3 data + ingest nodes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
resource "instaclustr_opensearch_cluster_v2" "my_test_cluster_example" { name = "my_test_cluster_example" opensearch_major_version = "2" sla_tier = "NON_PRODUCTION" pci_compliance_mode = false load_balancer = false private_network_cluster = false data_centre { cloud_provider = "AWS_VPC" name = "AWS_VPC_US_EAST_1" network = "10.0.0.0/16" number_of_racks = 3 private_link = false region = "US_EAST_1" } # Note: the "cluster_manager_nodes" block is a required block cluster_manager_nodes { dedicated_manager = false node_size = "SRH-DEV-t4g.small-5" } # Note: the "data_nodes" block is an optional block in this example data_nodes { node_count = 3 node_size = "SRH-DEV-t4g.small-5" } } |
This example provisions a 6-node cluster, with 3 cluster manager eligible nodes assigned with the roles of “data”, “ingest” and “cluster_manager”, and 3 data + ingest nodes assigned with the roles “data” and “ingest”.
Scenario 5: Provision an OpenSearch cluster with 3 dedicated manager nodes and 3 data + ingest nodes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
resource "instaclustr_opensearch_cluster_v2" "my_test_cluster_example" { name = "my_test_cluster_example" opensearch_major_version = "2" sla_tier = "NON_PRODUCTION" pci_compliance_mode = false load_balancer = false private_network_cluster = false data_centre { cloud_provider = "AWS_VPC" name = "AWS_VPC_US_EAST_1" network = "10.0.0.0/16" number_of_racks = 3 private_link = false region = "US_EAST_1" } # Note: the "cluster_manager_nodes" block is a required block cluster_manager_nodes { dedicated_manager = true node_size = "SRH-DM-DEV-t4g.small-5" } # Note: the "data_nodes" block becomes mandatory because dedicated_manager = true data_nodes { node_count = 3 node_size = "SRH-DEV-t4g.small-5" } } |
This example provisions a 6-node cluster, with 3 dedicated manager nodes assigned with the role of “cluster_manager”, and 3 data + ingest nodes assigned with the roles “data” and “ingest”.
Contact Instaclustr Support if there are any questions or issues with provisioning your cluster with the Instaclustr Terraform Provider V2.