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

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

  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
  # Un-comment the lifecycle when this is an update.

  lifecycle {
    ignore_changes = [mappings, aliases]
  }
}