Skip to content

Commit

Permalink
Dynamically set availability zone count using instance count and subn…
Browse files Browse the repository at this point in the history
…et count (#16)
  • Loading branch information
OlamideOl1 authored Dec 12, 2024
1 parent bd8cf4d commit de49ec9
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions opensearch.tf
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
data "aws_availability_zones" "available" {}

locals {
region = data.aws_region.current.name
name = "es-${var.es_application_name}"
region = data.aws_region.current.name
name = "es-${var.es_application_name}"
ideal_subnet_count = var.es_instance_count > 2 ? min(length(module.network.private_subnet_ids), 3) : var.es_instance_count
}

resource "aws_iam_service_linked_role" "elasticsearch" {
Expand Down Expand Up @@ -58,7 +59,7 @@ module "opensearch" {
instance_type = coalesce(var.es_instance_type, var.es_dedicated_master_type)

zone_awareness_config = {
availability_zone_count = length(module.network.private_subnet_ids) > 3 ? 3 : length(module.network.private_subnet_ids)
availability_zone_count = local.ideal_subnet_count
}

zone_awareness_enabled = true
Expand Down Expand Up @@ -101,7 +102,8 @@ module "opensearch" {
}

vpc_options = {
subnet_ids = length(module.network.private_subnet_ids) > 3 ? slice(module.network.private_subnet_ids, 0, 3) : module.network.private_subnet_ids
subnet_ids = slice(module.network.private_subnet_ids, 0, min(length(module.network.private_subnet_ids), local.ideal_subnet_count))

}

# Security Group rule example
Expand Down

0 comments on commit de49ec9

Please sign in to comment.