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

# create the actual index
resource "opensearch_index" "label_participant_v01" {
  name                   = "label_participant.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_participant]

  aliases = jsonencode({
    "label_participant_write" : {
      "is_write_index" : true
    },
    "label_participant_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]
  }
}
