opensearch-project / terraform-provider-opensearch

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

[BUG] Import of index resource doesn't include mapping configuration #135

Open jmaitrehenry opened 8 months ago

jmaitrehenry commented 8 months ago

What is the bug?

When I attempt to import the opensearch_index resource with mapping configured, it doesn't get imported into the state

How can one reproduce the bug?

Create an index with a mapping configuration:

resource opensearch_index "my-index" {
    name               = "my-index"
    mappings           = file("${path.module}/elasticsearch-mappings/my-index.mapping.json")
    number_of_replicas = 1
    number_of_shards   = 5
}

Remove it from the state and import it back:

terragrunt state rm opensearch_index.my-index
terragrunt import opensearch_index.enriched-contacts my-index

The new resource state doesn't have the mapping configuration:

terragrunt state show opensearch_index.my-index
# opensearch_index.my-index:
resource "opensearch_index" "my-index" {
    id                 = "my-index"
    name               = "my-index"
    number_of_replicas = "1"
    number_of_shards   = "5"
}

What is the expected behavior?

The mapping is imported.

What is your host/environment?

Provider:

  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.26.0"
    }

    opensearch = {
      source = "opensearch-project/opensearch"
      version = "2.1.0"
    }
  }

Terraform:

Terraform v1.5.7
on darwin_arm64
prudhvigodithi commented 8 months ago

[Untriage] Hey @jmaitrehenry thanks for reporting, looks to me like this is a similar issue https://github.com/opensearch-project/terraform-provider-opensearch/issues/71, if you are open can you please contribute and fix this bug? Thank you Adding @rblcoder

rblcoder commented 7 months ago

@prudhvigodithi When I try to call

mapping, err := osClient.GetMapping().Index(index).Do(ctx)

err shows elastic: Error 400 (Bad Request)

Variable index contains the name of the index.

xsnrg commented 7 months ago

My issue for this was closed referencing #71 . What are the chances of getting somebody on the core team to fix this? I don't know that the community has any PR work ready for fixing it, and it is fairly important to the usability of the provider.

prudhvigodithi commented 7 months ago

Hey @xsnrg when you mention core team are you referencing to the OpenSearch core engine and should a fix happen in core engine or can a fix be part of the terraform provider ? Adding @bbarani @phillbaker

xsnrg commented 7 months ago

@prudhvigodithi - a good question. My understanding is the fix is needed in the provider. I was referring to the primary contributors to the terraform-provider-opensearch project, and not to the actual Opensearch core engine team.

There are individuals here that are more familiar with the provider code, such as @bbarani and @phillbaker . They could probably knock this out fairly quickly if they have the time, vs. waiting for a community member to provide a PR. My hope is somebody close to the provider code could take a look and see if it is a quick win.