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

# create the actual index
resource "opensearch_index" "vectororder_detail_v01" {
  name               = "vectororder_detail.v01"
  number_of_replicas = "1"
  number_of_shards   = "3"
  refresh_interval   = "60s"
  force_destroy      = "true"
  max_result_window  = "10000"

  depends_on = [opensearch_index_template.vectororder_detail]

  # Lets try and use these from the clients instead of hardcoding the index name.
  aliases = jsonencode({
    "vectororder_detail_write" : {
      "is_write_index" : true
    },
    "vectororder_detail_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]
  }
}
