# Index for label search
resource "opensearch_index_template" "label" {
  name = "label"
  body = file("label_template.json")
}

# create the actual index
resource "opensearch_index" "label_v01" {
  name                   = "label.v01"
  number_of_replicas     = "1"
  number_of_shards       = "3"
  refresh_interval       = "60s"
  routing_partition_size = "1"
  force_destroy          = "true"

  depends_on = [opensearch_index_template.label]

  aliases = jsonencode({
    "label_write" : {
      "is_write_index" : true
    },
    "label_read" : {
      "is_write_index" : false
    }
  })

  # This is a workaround to prevent the index from being replaced when the resource is updated
  # mappings are managed at the index template level
  # https://github.com/opensearch-project/terraform-provider-opensearch/issues/175
  # Un-comment the lifecycle when this is an update.

  # lifecycle {
  #   ignore_changes = [mappings]
  # }
}
