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 index resource doesn't include the aliases #108

Open
sharathganga opened this issue Oct 20, 2023 · 6 comments
Open

[BUG] Import of index resource doesn't include the aliases #108

sharathganga opened this issue Oct 20, 2023 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@sharathganga
Copy link

What is the bug?

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

How can one reproduce the bug?

Provided an index that was created with aliases

{
  "ci-metrics-000001" : {
    "aliases" : {
      "ci-metrics" : {
        "is_write_index" : true
      }
    },
    "mappings" : { },
    "settings" : {
      "index" : {
        "number_of_shards" : "3",
        "plugins" : {
          "index_state_management" : {
            "rollover_alias" : "ci-metrics"
          }
        },
        "provided_name" : "ci-metrics-000001",
        "creation_date" : "1691569233793",
        "number_of_replicas" : "1",
        "uuid" : "Vm8occETQKqPtTpR5zyFeQ",
        "version" : {
          "created" : "135248027"
        }
      }
    }
  }
}

then run the terraform import command

terraform import opensearch_index.index[\"ci-metrics\"] ci-metrics-000001

but this is how the resource looks in the state

$ terraform state show opensearch_index.index[\"ci-metrics\"]
# opensearch_index.index["ci-metrics"]:
resource "opensearch_index" "index" {
    id                 = "ci-metrics-000001"
    name               = "ci-metrics-000001"
    number_of_replicas = "1"
    number_of_shards   = "3"
    rollover_alias     = "ci-metrics"
}

Finally when I run a terraform plan, it tells me that the index will replaced to add aliases

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create
-/+ destroy and then create replacement

Terraform will perform the following actions:

  # opensearch_index.index["ci-metrics"] must be replaced
-/+ resource "opensearch_index" "index" {
      + aliases            = jsonencode(
            {
              + ci-metrics = {
                  + is_write_index = true
                }
            } # forces replacement
        )
      + force_destroy      = false
      ~ id                 = "ci-metrics-000001" -> (known after apply)
        name               = "ci-metrics-000001"
      - number_of_replicas = "1" -> null
      ~ number_of_shards   = "3" -> (known after apply)
      ~ rollover_alias     = "ci-metrics" -> (known after apply)
    }
    ```
### What is the expected behavior?
Terraform should import the aliases field and/or any other missing fields

### What is your host/environment?
$ uname -a
Linux PBL244 5.15.90.1-microsoft-standard-WSL2 #1 SMP Fri Jan 27 02:56:13 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

$ terraform version 
Terraform v1.5.3
on linux_amd64
+ provider registry.terraform.io/hashicorp/aws v5.22.0
+ provider registry.terraform.io/opensearch-project/opensearch v2.0.0

Your version of Terraform is out of date! The latest version
is 1.6.2. You can update by downloading from https://www.terraform.io/downloads.html

I'm using AWS Opensearch 1.3 and provider version 2.0.0.
@sharathganga sharathganga added bug Something isn't working untriaged labels Oct 20, 2023
@peterzhuamazon
Copy link
Member

Hi @rblcoder @premkirank @SkollRyu @afrodidact @tranngocsongtruc could you take a look and add your thoughts?

cc: @prudhvigodithi

Thanks.

@c0rmichels
Copy link

I see the same behaviour
provider version 2.0.0, opensearch version 2.2.1

@prudhvigodithi
Copy link
Member

@rblcoder can you please take a look and add your thoughts ?

@rblcoder
Copy link
Collaborator

rblcoder commented Oct 31, 2023

rollover_alias is a computed attribute.
https://discuss.hashicorp.com/t/computed-attributes-and-plan-modifiers/45830/14#:~:text=The%20framework%20will%20automatically%20mark,prevent%20Terraform%20data%20consistency%20errors. says
The framework will automatically mark Computed attributes with null configuration as unknown (known after apply) during the plan, which is intentional to prevent Terraform data consistency errors.

@rblcoder
Copy link
Collaborator

rblcoder commented Oct 31, 2023

Also please try setting number_of_shards and number_of_replicas as follows that is as separate key/value pairs instead of within settings, documentation https://registry.terraform.io/providers/jamesanto/opensearch/latest/docs/resources/index -

resource "opensearch_index" "index" {
  name = "test-logs-000001"
  number_of_shards = 3
  number_of_replicas = 1

@sharathganga
Copy link
Author

@rblcoder number_of_shards and number_of_replicas on the index are being managed from opensearch_index_template resource

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: 📦 Backlog
Development

No branches or pull requests

5 participants