opensearch-project / terraform-provider-opensearch

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

[BUG] Planning failed when cluster_routing_allocation_enable is used opensearch_cluster_settings resource #181

Closed hajnej closed 2 months ago

hajnej commented 3 months ago

What is the bug?

terraform plan/apply fails to plan when cluster_routing_allocation_enable attribute is used in opensearch_cluster_settings resource.

Initial apply ends successfully. Any subsequent terraform plan or terraform apply fails with this error:

terraform apply
module.gcp-opensearch.opensearch_cluster_settings.global: Refreshing state... [id=settings]

Planning failed. Terraform encountered an error while generating this plan.

╷
│ Error: strconv.ParseBool: parsing "all": invalid syntax
│ 
│   with module.gcp-opensearch.opensearch_cluster_settings.global,
│   on ../../../../modules/gcp-opensearch/main.tf line 1, in resource "opensearch_cluster_settings" "global":
│    1: resource "opensearch_cluster_settings" "global" {

How can one reproduce the bug?

Create OpenSearch cluster and try to apply this Terraform configuration

resource "opensearch_cluster_settings" "global" {
   cluster_routing_allocation_enable = "all"
}

What is the expected behavior?

terraform plan, terraform apply succeeds.

What is your host/environment?

OpenSearch cluster 2.11 deployed on kind Kubernetes Cluster via OpenSearch Operator

Do you have any screenshots?

Do you have any additional context?

curl -X GET https://opensearch.127.0.0.1.nip.io/_cluster/settings

{
  "persistent": {
    "action": {
      "auto_create_index": "true",
      "destructive_requires_name": "true"
    },
    "cluster": {
      "routing": {
        "allocation": {
          "node_concurrent_recoveries": "4",
          "node_initial_primaries_recoveries": "8",
          "enable": "all",
          "total_shards_per_node": "1000"
        }
      },
      "max_shards_per_node": "10"
    },
    "indices": {
      "breaker": {
        "fielddata": {
          "limit": "20%"
        },
        "total": {
          "limit": "90%"
        }
      },
      "recovery": {
        "max_bytes_per_sec": "40mb"
      }
    },
    "plugins": {
      "index_state_management": {
        "template_migration": {
          "control": "-1"
        }
      }
    }
  },
  "transient": {
    "cluster": {
      "routing": {
        "allocation": {
          "enable": "all"
        }
      }
    }
  }
}
hajnej commented 3 months ago

I am Golang / Terraform providers developer newbie but a quick guess is that https://github.com/opensearch-project/terraform-provider-opensearch/blob/174c272a967fbb913abbe3e5baba4b677cc6666b/provider/resource_opensearch_cluster_settings.go#L63 should be moved into stringClusterSettings

rblcoder commented 3 months ago

@hajnej Your solution is working for me, do go ahead if you would like to contribute the same.