mongodb / terraform-provider-mongodbatlas

Terraform MongoDB Atlas Provider: Deploy, update, and manage MongoDB Atlas infrastructure as code through HashiCorp Terraform
https://registry.terraform.io/providers/mongodb/mongodbatlas
Mozilla Public License 2.0
244 stars 170 forks source link

mongodbatlas_search_index does not allow for name changing #1613

Open icco opened 11 months ago

icco commented 11 months ago

Terraform CLI and Terraform MongoDB Atlas Provider Version

Terraform v1.5.7
on darwin_arm64
+ provider registry.terraform.io/hashicorp/aws v4.67.0
+ provider registry.terraform.io/hashicorp/kubernetes v2.23.0
+ provider registry.terraform.io/hashicorp/null v3.2.1
+ provider registry.terraform.io/hashicorp/random v3.5.1
+ provider registry.terraform.io/mongodb/mongodbatlas v1.12.2
+ provider registry.terraform.io/sumologic/sumologic v2.27.0

Terraform Configuration File

resource "mongodbatlas_search_index" "v2_initiative_props_search_index" {
  name            = "test"
  project_id      = var.atlas_project_id
  cluster_name    = "test"
  database        = "time-service"
  collection_name = "initiative_props"

  analyzer         = "lucene.standard"
  search_analyzer  = "lucene.standard"
  mappings_dynamic = false
  mappings_fields = jsonencode(
    {
      initiative = {
        dynamic = false
        fields = {
          client = {
            dynamic = false
            fields = {
              callSign = local.atlas_search_string_index_definition
              name     = local.atlas_search_string_index_definition
            }
            type = "document"
          }
          callSign = local.atlas_search_string_index_definition
          name     = local.atlas_search_string_index_definition
        }
        type = "document"
      }
      nickname = local.atlas_search_string_index_definition
      customerId = {
        type = "objectId"
      }
      userId = {
        type = "objectId"
      }
    }
  )

  analyzers = jsonencode(local.atlas_search_analyzers)
}

locals {
  laurel_standard_atlas_search_analyzer = {
    charFilters = [
      {
        type = "icuNormalize"
      },
      {
        mappings = {
          "("  = " "
          ")"  = " "
          ","  = " "
          "-"  = " "
          "."  = " "
          "/"  = " "
          ":"  = " "
          ";"  = " "
          "\\" = " "
          "_"  = " "
          "|"  = " "
        },
        type = "mapping"
      }
    ]
    name = "laurel.standard",
    tokenFilters = [
      {
        type = "icuFolding"
      },
      {
        type = "englishPossessive"
      },
      {
        type = "lowercase"
      },
      {
        type = "kStemming"
      }
    ],
    tokenizer = {
      type = "standard"
    }
  }

  laurel_standard_egrams_atlas_search_analyzer = {
    charFilters = [
      {
        type = "icuNormalize"
      },
      {
        mappings = {
          "("  = " "
          ")"  = " "
          ","  = " "
          "-"  = " "
          "."  = " "
          "/"  = " "
          ":"  = " "
          ";"  = " "
          "\\" = " "
          "_"  = " "
          "|"  = " "
        },
        type = "mapping"
      }
    ]
    name = "laurel.standard-egrams",
    tokenFilters = [
      {
        type = "icuFolding"
      },
      {
        type = "englishPossessive"
      },
      {
        type = "lowercase"
      },
      {
        type = "kStemming"
      },
      {
        maxGram         = 10,
        minGram         = 2,
        termNotInBounds = "include",
        type            = "edgeGram"
      }
    ],
    tokenizer = {
      type = "standard"
    }
  }

  laurel_exact_atlas_search_analyzer = {
    charFilters = [
      {
        type = "icuNormalize"
      }
    ]
    name = "laurel.exact"
    tokenFilters = [
      {
        type = "icuFolding"
      },
      {
        type = "lowercase"
      }
    ]
    tokenizer = {
      type = "whitespace"
    }
  }

  laurel_exact_egrams_atlas_search_analyzer = {
    charFilters = [
      {
        type = "icuNormalize"
      }
    ]
    name = "laurel.exact-egrams",
    tokenFilters = [
      {
        type = "icuFolding"
      },
      {
        type = "lowercase"
      },
      {
        maxGram         = 15,
        minGram         = 5,
        termNotInBounds = "include",
        type            = "edgeGram"
      }
    ],
    tokenizer = {
      type = "whitespace"
    }
  }

  atlas_search_analyzers = [
    local.laurel_standard_atlas_search_analyzer,
    local.laurel_standard_egrams_atlas_search_analyzer,
    local.laurel_exact_atlas_search_analyzer,
    local.laurel_exact_egrams_atlas_search_analyzer,
  ]

  atlas_search_string_index_definition = {
    analyzer = "laurel.standard-egrams"
    multi = {
      exact = {
        analyzer       = "laurel.exact-egrams"
        searchAnalyzer = "laurel.exact"
        type           = "string"
      }
    }
    searchAnalyzer = "laurel.standard"
    type           = "string"
  }
}

Steps to Reproduce

  1. Create a search index using the above code (or any other search index, doesn't matter in our experience)
  2. Change the name of the search index ("test_v2" for example)
  3. Apply

Expected Behavior

Either the search index should be recreated with the new name or the name should be changed.

Actual Behavior

It says it's going to change the name and doesn't.

Debug Output

N/A

Crash Output

N/A

Additional Context

N/A

References

N/A

github-actions[bot] commented 11 months ago

Thanks for opening this issue! Please make sure you've followed our guidelines when opening the issue. In short, to help us reproduce the issue we need:

The ticket INTMDB-1275 was created for internal tracking.

andreaangiolillo commented 11 months ago

Hi @icco Thanks for opening the issue. I was able to reproduce the bug. The issue is related to a bug with the Atlas endpoint rather than a bug with the provider. I am going to follow up internally to fix the endpoint. I will add an update as soon as the bug is fixed. Thanks

Zuhairahmed commented 11 months ago

Adding https://jira.mongodb.org/browse/CLOUDP-210605 for internal tracking purposes. As an update we are working on fix but this one is likely going to be several months away. Thanks for raising issue and will share next update when we can.