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] opensearch_index behavior when trying to delete an index via Terraform #85

Closed
jlustin opened this issue Sep 22, 2023 · 17 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@jlustin
Copy link

jlustin commented Sep 22, 2023

What is the bug?

Hi, I am currently looking at ways to delete an index and the behavior I am seeing when modifying a opensearch_index resource is very confusing.

  1. When modifying aliases of an existing index, the index gets destroyed then recreated by Terraform, logs saying that the index must be replaced, in which case the index is destroyed and recreated. However, when modifying other attributes such as number_of_replicas or refresh_interval, the index gets updated in place and the index is kept.
  2. When setting force_destroy to true or flicking it from false to true, Terraform indicates in the plan that the index is changed, but does not actually destroy the index.
  3. When simply removing the index module from the repository in an attempt to delete it, I get an error saying that Provider configuration not present. This also happens whether I delete the targeted index manually from the OS dashboard or not; so if I delete the index manually and do not remove the module, the index will get recreated, and if I remove the module, I get that error. I am able to get through this stage by doing a state rm on the module, but this does not actually delete the index either.

How can one reproduce the bug?

Create an index without aliases nor force_destroy:

  1. Set aliases for the index. The index will get destroyed and recreated.
  2. Set force_destroy to true. Nothing happens to the index.
  3. Remove the index module. Plan fails.

What is the expected behavior?

  1. Aliases for given index are updated but index is not recreated. Right now, since the index is recreated, all documents are lost.
  2. Index is destroyed whether it contains documents or not.
  3. I would expect the index to be deleted by Terraform if its module is removed from the Terraform repository, which is what I am trying to achieve.

What is your host/environment?

Terraform v1.3.5
on linux_amd64
...
+ provider registry.terraform.io/opensearch-project/opensearch v1.0.0

Do you have any additional context?

Context = I am seeing this behavior when trying to delete an index.
What would be the correct way to achieve deleting an index that was created using the terraform provider? Is this supported somehow?

@jlustin jlustin added bug Something isn't working untriaged labels Sep 22, 2023
@prudhvigodithi
Copy link
Member

Hey @jlustin I assume you are using the latest version of the provider https://registry.terraform.io/providers/opensearch-project/opensearch/2.0.0
In this comment I have tested creating index and index template and able to create and destroy, please check #72 (comment)
Adding @rblcoder @afrodidact @premkirank
Thank you

@premkirank
Copy link
Contributor

@prudhvigodithi I would like to work on this

@prudhvigodithi
Copy link
Member

Thanks assigned to your @premkirank.

@premkirank
Copy link
Contributor

I am starting on this issue from now. Had been working on some minor bugs etc to get a hang of the repo. Sorry for the delay

@premkirank
Copy link
Contributor

premkirank commented Nov 18, 2023

@jlustin I have been able to follow along until step 2 and been able to verify what you have said. I am not able to understand step 3 i.e deleting an index module. How can I delete an index module, is there some API for this?

@prudhvigodithi
Copy link
Member

Hey @jlustin as per the discussion here #83 (comment), the index should not get deleted when configured an alias using the provider? Can you please confirm if you are using the latest version? Thanks

@jlustin
Copy link
Author

jlustin commented Nov 20, 2023

@premkirank Thanks for the update. For step 3, I just meant deleting the config of the index from the files

@jlustin
Copy link
Author

jlustin commented Nov 20, 2023

@prudhvigodithi This was initially produced when using registry.terraform.io/opensearch-project/opensearch v1.0.0 as specified above; I will try once more after doing an update

@jlustin
Copy link
Author

jlustin commented Nov 23, 2023

Hi both, I'm using v2.1.0 now and seeing the same behavior as initially described.

@prudhvigodithi This is the output when I try modifying the alias of an index via the provider; the index would get replaced:
image

@premkirank
Copy link
Contributor

@premkirank Thanks for the update. For step 3, I just meant deleting the config of the index from the files

@jlustin could you just provide a sample for this file after deleting the config. It will help make it clear.

@imanis
Copy link

imanis commented May 14, 2024

HI @premkirank : can you please start by the first step (Set aliases for the index. The index will get destroyed and recreated.)
Is that a normal behavior ?
Adding an alias to an index should not force recreating the index.

@anuborah
Copy link

anuborah commented Sep 6, 2024

HI @premkirank @prudhvigodithi Is there any update on the above bug when it will be fixed? Adding an alias to the existing index the index gets deleted :(

@prudhvigodithi
Copy link
Member

Hey @anuborah thanks for sharing your thoughts, I agree this bug has to be fixed, we can looking for some contributors, is it possible for you to fix this bug by creating a PR? I'm happy to help and troubleshoot here. We can talk more in this slack channel as well https://opensearch.slack.com/archives/C051ZNQ16KG.
Thank you
Adding @imanis @jlustin @premkirank @rblcoder @getsaurabh02

@prudhvigodithi
Copy link
Member

prudhvigodithi commented Sep 17, 2024

I have a PR open for this bug #212, we can now update the aliases section on existing opensearch_index without destroying or force update.

  aliases = jsonencode(
   {
    "log": {
      "is_write_index": true
    }
  }
  )

Example output when the index is created with no aliases


curl http://localhost:9200/sample/_alias  -u 'admin:myStrongPassword123@456' | jq '.'
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    25  100    25    0     0   8389      0 --:--:-- --:--:-- --:--:-- 12500
{
  "sample": {
    "aliases": {}
  }
}

Example terraform apply output when the index is created and aliases is added

# opensearch_index.index will be updated in-place
  ~ resource "opensearch_index" "index" {
      + aliases            = jsonencode(
            {
              + log = {
                  + is_write_index = true
                }
            }
        )
        id                 = "sample"
        name               = "sample"
        # (4 unchanged attributes hidden)
    }
    
curl http://localhost:9200/sample/_alias  -u 'admin:myStrongPassword123@456' | jq '.'
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    54  100    54    0     0  19244      0 --:--:-- --:--:-- --:--:-- 27000
{
  "sample": {
    "aliases": {
      "log": {
        "is_write_index": true
      }
    }
  }
}

Thanks
@getsaurabh02

@prudhvigodithi prudhvigodithi self-assigned this Sep 17, 2024
@prudhvigodithi
Copy link
Member

Hey @jlustin the index cannot be deleted if the documents are present thats the behavior of the OpenSearch and nothing to do with the terraform provider.

@prudhvigodithi
Copy link
Member

The terraform provider 2.3.1 is released with opensearch_index aliases bug fix, @anuborah @imanis @jlustin please take a look.
Thanks

@prudhvigodithi prudhvigodithi moved this from Backlog to 🏗 In progress in Engineering Effectiveness Board Sep 23, 2024
@prudhvigodithi
Copy link
Member

Closing this issue since the terraform provider 2.3.1 is released with opensearch_index aliases bug fix, please feel free to add a comment or re-open if required.
Thank you
@getsaurabh02

@github-project-automation github-project-automation bot moved this from 🏗 In progress to ✅ Done in Engineering Effectiveness Board Sep 29, 2024
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
Status: ✅ Done
Development

No branches or pull requests

5 participants