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

# create the actual index
resource "opensearch_index" "testing_v01" {
  name                   = "testing.v01"
  number_of_replicas     = "1"
  number_of_shards       = "1"

  depends_on = [opensearch_index_template.testing]

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