[Bug] Incorrect detection of changes in index mappings when using index template
Describe the bug We have encountered an issue with the elasticsearch terraform provider where it incorrectly detects changes in index mappings during subsequent terraform runs when using an index template to define the mappings.
To Reproduce Steps to reproduce the behavior:
- Define an index template and index that matches the pattern defined in index template
resource "elasticstack_elasticsearch_index_template" "sample-index-template" {
name = "sample-index-template"
priority = 1
index_patterns = ["sample.index*"]
template {
mappings = jsonencode({
"properties" : {
"summary" : {
"type" : "text",
"fields" : {
"keyword" : {
"ignore_above" : 256,
"type" : "keyword"
}
}
}
}
})
}
resource "elasticstack_elasticsearch_index" "sample-index" {
name = "sample-index-1"
alias {
name = "sampleA"
is_write_index = true
}
}
- Run terraform plan and apply. Ensure the sample-index is created and mappings are applied.
- Run terraform plan again. It incorrectly detects change in the index mappings even though no changes were made to the mappings or the index template.
# elasticstack_elasticsearch_index.sample-index must be replaced
-/+ resource "elasticstack_elasticsearch_index" "sample-index" {
~ id = "asdvv/sample-index-1" -> (known after apply)
~ mappings = jsonencode(
- properties = {
- summary = {
- fields = {
- keyword = {
- ignore_above = 256
- type = "keyword"
}
}
- type = "text"
}
} # forces replacement
)
name = "sample-index-1"
# (1 unchanged block hidden)
}
Expected behavior Terraform should not detect changes in the index mappings during subsequent runs if the mappings are defined in an index template and have not been modified.
Versions (please complete the following information):
- OS: MacOS
- Terraform Version - v1.5.3 on darwin_amd64
- Provider version - v0.11.0
I have the same problem. Here is the workaround I'm using.
resource "elasticstack_elasticsearch_index" "sample-index" {
name = "sample-index-1"
lifecycle {
ignore_changes = [
mappings,
]
}
}
+1
Freshly created index template using elasticstack_elasticsearch_index_template and jsonencode() for mappings results in always trying to update it