opensearch-project / terraform-provider-opensearch

https://registry.terraform.io/providers/opensearch-project/opensearch
Apache License 2.0
73 stars 55 forks source link

[BUG] Terraform state for opensearch_index resource should include aliases on import #190

Open thejettanderson opened 1 month ago

thejettanderson commented 1 month ago

What is the bug?

When importing an existing opensearch index, the captured/imported terraform state doesn't include any indices, which results in a plan/apply for the imported opensearch_index resource replacing the already created index because the alias isn't captured.

How can one reproduce the bug?

Perform a terraform import opensearch_index.my-example-index-v1 my-example-index-v1 Perform a terraform show state opensearch_index.my-example-index-v1. Look at the output and see that the aliases block is missing for my index with an alias of my-example-index when it's created and shows up in the Opensearch Kibana.

What is the expected behavior?

Performing a terraform import should import any aliases that already exist for opensearch indices. Output of a terraform show state after performing a terraform import should look like this

resource "opensearch_index" "my-example-index-v1" {
  id               = "my-example-index-v1"
  aliases      = jsonencode(
    {
      "my-example-index" = {}
    }
  )
  mappings = jsonencode(
    {
      ...
    }
  )
}

but instead performing a terraform show state opensearch_index.my-example-index-v1 gives this:

resource "opensearch_index" "my-example-index-v1" {
  id               = "my-example-index-v1"
  mappings = jsonencode(
    {
      ...
    }
  )
}

resulting in a terraform apply replacing the existing index even though the my-example-index alias already exists for the index.

What is your host/environment?

Docker/k8s, ubuntu base image.

Do you have any additional context?

Add any other context about the problem.

dblock commented 3 weeks ago

Catch All Triage - 1 2 3 4 5 6