Created
January 12, 2022 14:42
Revisions
-
jakzal created this gist
Jan 12, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ # OpenSearch terraform configuration for local development Based on docker-compose.yml from OpenSearch: https://opensearch.org/samples/docker-compose.yml ## How to apply? ```bash terraform init terraform plan terraform apply ``` This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ terraform { required_providers { docker = { source = "kreuzwerker/docker" version = "~> 2.13.0" } } } provider "docker" {} This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,80 @@ locals { opensearch_node_count = 2 opensearch_nodes = { for index in range(1, local.opensearch_node_count + 1) : index => "${var.project_name}-opensearch-node${index}" } } resource "docker_image" "opensearch" { name = "opensearchproject/opensearch:latest" keep_locally = false } resource "docker_image" "opensearch_dashboards" { name = "opensearchproject/opensearch-dashboards:latest" keep_locally = false } resource "docker_network" "opensearch_network" { name = "${var.project_name}-opensearch-net" } resource "docker_container" "opensearch_node" { for_each = local.opensearch_nodes image = docker_image.opensearch.latest name = each.value env = [ "cluster.name=opensearch-cluster", "node.name=${each.value}", "discovery.seed_hosts=${join(",", [for k, v in local.opensearch_nodes : v])}", "cluster.initial_master_nodes=${join(",", [for k, v in local.opensearch_nodes : v])}", "bootstrap.memory_lock=true", "OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m" ] ulimit { name = "memlock" soft = -1 hard = -1 } ulimit { name = "nofile" soft = 65536 hard = 65536 } volumes { container_path = "/usr/share/opensearch/data" volume_name = "opensearch-data${each.key}" } ports { internal = 9200 external = 9200 + each.key - 1 } ports { internal = 9600 external = 9600 + each.key - 1 } networks_advanced { name = docker_network.opensearch_network.name } } resource "docker_container" "opensearch_dashboards" { image = docker_image.opensearch_dashboards.latest name = "${var.project_name}-opensearch-dashboards" env = ["OPENSEARCH_HOSTS=${jsonencode([for k, v in docker_container.opensearch_node : "https://${v.name}:9200"])}"] ports { internal = 5601 external = 5601 } networks_advanced { name = docker_network.opensearch_network.name } } output "opensearch_nodes" { value = [for index, node in docker_container.opensearch_node : node.name] } output "opensearch_dashboards" { value = [docker_container.opensearch_dashboards.name] } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ variable "project_name" { description = "Name of the project" type = string default = "foo" }