Skip to content

[Bug] Incorrect detection of changes in index mappings when using index templateΒ #563

@pravan07

Description

@pravan07

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:

  1. 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
  }
}
  1. Run terraform plan and apply. Ensure the sample-index is created and mappings are applied.
  2. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions