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] Import of the opensearch_index resource does not include the analysis attributes #225

Open
gonz-cint opened this issue Dec 6, 2024 · 0 comments
Labels
bug Something isn't working untriaged

Comments

@gonz-cint
Copy link

gonz-cint commented Dec 6, 2024

What is the bug?

When importing an opensearch_index resource using the OpenSearch provider for Terraform, the analysis attributes (e.g., analysis_analyzer, analysis_tokenizer, analysis_filter, analysis_char_filter) are not included in the state of the imported resource. As a result, Terraform sees these as differences and forces the resource to be replaced during the next plan/apply cycle.

How can one reproduce the bug?

1- Create an OpenSearch index resource with analysis attributes (e.g., analyzers, tokenizers, filters).
2- Import the resource using the OpenSearch provider for Terraform (terraform import or the import block).
3- Run terraform state show on the imported resource and notice that the analysis attributes are missing.
4- Run terraform plan to compare the imported resource against the configuration, and observe that Terraform plans to replace the resource because the analysis attributes are seen as missing.

What is the expected behavior?

When importing an OpenSearch index resource, all attributes, including analysis attributes, should be correctly imported into the state. Terraform should not force replacement of the resource if the imported resource matches the configuration.

What is your host/environment?

Terraform version: 1.8.5
OpenSearch provider version: 2.3.1
OpenSearch version: 2.13

Do you have any additional context?

The following index was imported into the state running terraform import:

Configuration Block:

resource "opensearch_index" "example" {
  name                 = "example-index"
  number_of_shards     = 1
  number_of_replicas   = 0
  analysis_analyzer    = file("analyzers.json")
  analysis_tokenizer   = file("tokenizers.json")
  analysis_filter           = file("filters.json")
  analysis_char_filter = file("char_filters.json")
}

the analysis objects do exist in the resource already, however after importing this is the output of terraform state show:

resource "opensearch_index" "example" {
  id                 = "example-index"
  name               = "example-index"
  number_of_shards   = 1
  number_of_replicas = 0
}

Therefore a plan triggers an index replacement, as it sees the analysis objects as additions:

  # opensearch_index.example must be replaced
- resource "opensearch_index" "example" {
    analysis_analyzer    = ...
    analysis_tokenizer   = ...
    analysis_filter      = ...
    analysis_char_filter = ...
    ...
}
@gonz-cint gonz-cint added bug Something isn't working untriaged labels Dec 6, 2024
@gonz-cint gonz-cint changed the title [BUG] Import of the index resource does not include the analysis attributes [BUG] Import of the opensearch_index resource does not include the analysis attributes Dec 9, 2024
gonz-cint added a commit to gonz-cint/terraform-provider-opensearch that referenced this issue Dec 11, 2024
Previously, when importing an existing index, the analysis configuration
(analyzers, tokenizers, filters, char_filters, and normalizers) was not
fully populated into the Terraform state. As a result, users would not see
these analysis settings after import, leading to missing or incomplete
configurations in state.

This commit introduces logic to reconstruct nested analysis objects from
the flattened `index.analysis.*` keys returned by OpenSearch on import. By
converting these flattened keys back into a nested JSON structure, the
imported index state now includes the analysis settings as users typically
define them in their Terraform configuration.

**Note**: This change may reveal differences for existing configurations if
they rely on unquoted numeric values or trailing whitespace in
analysis-related JSON. Such configurations may now produce diffs where they
did not before, potentially resulting in forced replacements.

Issues Resolved
gonz-cint added a commit to gonz-cint/terraform-provider-opensearch that referenced this issue Dec 11, 2024
Previously, when importing an existing index, the analysis configuration
(analyzers, tokenizers, filters, char_filters, and normalizers) was not
fully populated into the Terraform state. As a result, users would not see
these analysis settings after import, leading to missing or incomplete
configurations in state.

This commit introduces logic to reconstruct nested analysis objects from
the flattened `index.analysis.*` keys returned by OpenSearch on import. By
converting these flattened keys back into a nested JSON structure, the
imported index state now includes the analysis settings as users typically
define them in their Terraform configuration.

**Note**: This change may reveal differences for existing configurations if
they rely on unquoted numeric values or trailing whitespace in
analysis-related JSON. Such configurations may now produce diffs where they
did not before, potentially resulting in forced replacements.

Signed-off-by: Gonzalo Arce <[email protected]>
gonz-cint added a commit to gonz-cint/terraform-provider-opensearch that referenced this issue Dec 11, 2024
Previously, when importing an existing index, the analysis configuration
(analyzers, tokenizers, filters, char_filters, and normalizers) was not
fully populated into the Terraform state. As a result, users would not see
these analysis settings after import, leading to missing or incomplete
configurations in state.

This commit introduces logic to reconstruct nested analysis objects from
the flattened `index.analysis.*` keys returned by OpenSearch on import. By
converting these flattened keys back into a nested JSON structure, the
imported index state now includes the analysis settings as users typically
define them in their Terraform configuration.

**Note**: This change may reveal differences for existing configurations if
they rely on unquoted numeric values or trailing whitespace in
analysis-related JSON. Such configurations may now produce diffs where they
did not before, potentially resulting in forced replacements.

Signed-off-by: Gonzalo Arce <[email protected]>
gonz-cint added a commit to gonz-cint/terraform-provider-opensearch that referenced this issue Dec 11, 2024
Previously, when importing an existing index, the analysis configuration
(analyzers, tokenizers, filters, char_filters, and normalizers) was not
fully populated into the Terraform state. As a result, users would not see
these analysis settings after import, leading to missing or incomplete
configurations in state.

This commit introduces logic to reconstruct nested analysis objects from
the flattened `index.analysis.*` keys returned by OpenSearch on import. By
converting these flattened keys back into a nested JSON structure, the
imported index state now includes the analysis settings as users typically
define them in their Terraform configuration.

**Note**: This change may reveal differences for existing configurations if
they rely on unquoted numeric values or trailing whitespace in
analysis-related JSON. Such configurations may now produce diffs where they
did not before, potentially resulting in forced replacements.

Signed-off-by: Gonzalo Arce <[email protected]>
gonz-cint added a commit to gonz-cint/terraform-provider-opensearch that referenced this issue Dec 11, 2024
Previously, when importing an existing index, the analysis configuration
(analyzers, tokenizers, filters, char_filters, and normalizers) was not
fully populated into the Terraform state. As a result, users would not see
these analysis settings after import, leading to missing or incomplete
configurations in state.

This commit introduces logic to reconstruct nested analysis objects from
the flattened `index.analysis.*` keys returned by OpenSearch on import. By
converting these flattened keys back into a nested JSON structure, the
imported index state now includes the analysis settings as users typically
define them in their Terraform configuration.

**Note**: This change may reveal differences for existing configurations if
they rely on unquoted numeric values or trailing whitespace in
analysis-related JSON. Such configurations may now produce diffs where they
did not before, potentially resulting in forced replacements.

Signed-off-by: Gonzalo Arce <[email protected]>
gonz-cint added a commit to gonz-cint/terraform-provider-opensearch that referenced this issue Dec 11, 2024
Previously, when importing an existing index, the analysis configuration
(analyzers, tokenizers, filters, char_filters, and normalizers) was not
fully populated into the Terraform state. As a result, users would not see
these analysis settings after import, leading to missing or incomplete
configurations in state.

This commit introduces logic to reconstruct nested analysis objects from
the flattened `index.analysis.*` keys returned by OpenSearch on import. By
converting these flattened keys back into a nested JSON structure, the
imported index state now includes the analysis settings as users typically
define them in their Terraform configuration.

**Note**: This change may reveal differences for existing configurations if
they rely on unquoted numeric values or trailing whitespace in
analysis-related JSON. Such configurations may now produce diffs where they
did not before, potentially resulting in forced replacements.

Signed-off-by: Gonzalo Arce <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working untriaged
Projects
Status: 🆕 New
Development

No branches or pull requests

1 participant