Skip to content

[Bug] Error 400 resource_already_exists_exception when replacing an index #966

@BardiaN

Description

@BardiaN

Describe the bug
Changing mapping_coerce on an index's mapping will trigger a replace. But the provider tries first to create the index which is not possible as it already exists.
I even tried adding create_before_destroy = false which is the default terraform behavior but it didn't work as expected.

lifecycle {
    create_before_destroy = false
  }

To Reproduce
Steps to reproduce the behavior:

  1. TF configuration used
resource "elasticstack_elasticsearch_index" "index" {
  name                = "index-one"

  mappings = jsonencode({
    properties = {
      name = {
        type = "text"
      }
   }
   })
  number_of_shards   = 1
  number_of_replicas = 1
  search_idle_after  = "20s"
  mapping_coerce     = false
}
  1. terraform apply to create the index
  2. Then change the mapping_coerce to true
  3. terraform apply to apply the coerce
  4. The plan will look like this :
Plan: 1 to add, 0 to change, 1 to destroy.
  1. Then enter yes to apply.
  2. Provider will try to create the resource first which causes the error:
elasticstack_elasticsearch_index.index: Creating...

│ This is a bug in the provider, which should be reported in the provider's own issue tracker.
╷
│ Error: Unable to create index: index
│ 
│   with elasticstack_elasticsearch_index.index,
│   on ./elastic-search.tf line 3, in resource "elasticstack_elasticsearch_index" "index":
│    3: resource "elasticstack_elasticsearch_index" "index" {
│ 
│ Failed with: {"error":{"root_cause":[{"type":"resource_already_exists_exception","reason":"index
│ [index/<ID>] already
│ exists","index_uuid":"<ID>","index":"index"}],"type":"resource_already_exists_exception","reason":"index
│ [index/<ID>] already
│ exists","index_uuid":"<ID>","index":"index"},"status":400}
╵

Expected behavior
The provider should respect create_before_destroy. In this case it means it has to destroy the index first and then create the new one.

Versions (please complete the following information):

  • OS: Mac OS Sequoia 15.1 (24B83)
  • Terraform v1.8.5
  • Provider version 0.11.12
  • Elasticsearch Version 7.17

Additional context

I also tried using alias, had the same result

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