terraform-provider-elasticstack icon indicating copy to clipboard operation
terraform-provider-elasticstack copied to clipboard

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

Open pravan07 opened this issue 1 year ago • 1 comments

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

pravan07 avatar Feb 07 '24 18:02 pravan07

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,
    ]
  }
}

aizerin avatar Aug 13 '24 12:08 aizerin

+1 Freshly created index template using elasticstack_elasticsearch_index_template and jsonencode() for mappings results in always trying to update it

lucasmat7 avatar Jan 29 '25 14:01 lucasmat7