Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
BardiaN opened this issue Dec 19, 2024 · 0 comments
Open
Labels
bug Something isn't working
Milestone

Comments

@BardiaN
Copy link

BardiaN commented Dec 19, 2024

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

@BardiaN BardiaN added the bug Something isn't working label Dec 19, 2024
@Kushmaro Kushmaro added this to the 0.14.0 milestone Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants