opensearch-project / terraform-provider-opensearch

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

[BUG] opensearch_index number_of_replicas is optional but breaks on subsequent applies if unset #52

Open arichtman-srt opened 1 year ago

arichtman-srt commented 1 year ago

What is the bug?

Terraform tries to set the number of replicas back to null, which will never work.

How can one reproduce the bug?

  1. Create a resource block of opensearch_index type and set the only required property, name
  2. Apply the Terraform, the index should now be created
  3. Terraform plan, it should show a diff on the property number_of_replicas
  4. Terraform apply, it will fail trying to set number_of_replicas to null

What is the expected behavior?

Either: A) It's possible to set replica count to nothing, in which case Terraform does so B) Number of replicas property should be mandatory

What is your host/environment?

$ uname -a && terraform -version

Darwin bne-nb-ariel 22.5.0 Darwin Kernel Version 22.5.0: Thu Jun  8 22:21:34 PDT 2023; root:xnu-8796.121.3~7/RELEASE_ARM64_T8112 arm64 arm Darwin
Terraform v1.3.9
on darwin_arm64
+ provider registry.terraform.io/hashicorp/aws v5.7.0
+ provider registry.terraform.io/opensearch-project/opensearch v1.0.0

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

Do you have any screenshots?

image

image

Do you have any additional context?

Technically it's correct that replica count isn't required to create an index. But I'm no software philosopher.

peterzhuamazon commented 1 year ago

[Triage] Adding @prudhvigodithi to take a look on this. Thanks.

prudhvigodithi commented 1 year ago

Hey @arichtman-srt can you please test with the latest release? https://registry.terraform.io/providers/opensearch-project/opensearch/2.0.0-beta.1 Thank you

rlanore commented 9 months ago

Tested today with 2.1.0 and no working with this example:

Example from doc opensearch_index_template resource are not working. I had to update the json.

# Create an index template
resource "opensearch_index_template" "logs_1" {
  name = "logs_1"
  body = <<EOF
{
  "index_patterns": [ "logs*" ],
  "template": {
    "settings": {
      "index": {
        "number_of_shards": "1",
        "number_of_replicas": "0",
        "refresh_interval": "5s"
      }
    }
  }
}
EOF
}

# Create a simple index
resource "opensearch_index" "logs-01" {
  name               = "logs-01"
}

as output

Terraform will perform the following actions:

  # opensearch_index.logs-01 will be updated in-place
  ~ resource "opensearch_index" "logs-01" {
        id                 = "logs-01"
        name               = "logs-01"
      - number_of_replicas = "0" -> null
      - refresh_interval   = "5s" -> null
        # (2 unchanged attributes hidden)
    }
Plan: 0 to add, 1 to change, 0 to destroy.
opensearch_index.logs-01: Modifying... [id=logs-01]
╷
│ Error: elastic: Error 400 (Bad Request): failed to parse setting [index.refresh_interval] with value [] as a time value: unit is missing or unrecognized [type=illegal_argument_exception]
│
│   with opensearch_index.logs-01,
│   on main.tf line 50, in resource "opensearch_index" "logs-01":
│   50: resource "opensearch_index" "logs-01" {
rlanore commented 9 months ago

As a workaround

# Create a simple index
resource "opensearch_index" "logs-01" {
  name               = "logs-01"
  lifecycle {
    ignore_changes = [
      number_of_replicas,
      refresh_interval
    ]
  }
}