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

# create the actual index
resource "opensearch_index" "conflict_v01" {
  name                   = "conflict.v01"
  number_of_replicas     = "1"
  number_of_shards       = "5"

  depends_on = [opensearch_index_template.conflict]

  aliases = jsonencode({
    "conflict_write" : {
      "is_write_index" : true
    },
    "conflict_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

  lifecycle {
    ignore_changes = [mappings, aliases]
  }
}