[Bug] Cannot create index with number_of_replicas=0
Describe the bug
I've tried to create an index with the parameter number_of_replicas=0, but in an elasticsearch instance, I've got an index with number_of_replicas=1.
To Reproduce Steps to reproduce the behavior:
- Define index in a terraform code:
resource "elasticstack_elasticsearch_index" "example" {
name = "example"
number_of_shards = 1
number_of_replicas = 0
}
- Run the terraform plan & terraform plan commands
- Check index settings and make sure index.number_of_replicas = 1.
Expected behavior
The created index should have index.number_of_replicas = 0 instead of index.number_of_replicas = 0
Versions (please complete the following information):
- OS: macOS
- Terraform Version: v1.1.7
- Provider version: 0.5.0
- Elasticsearch Version: 8.3.2
The root cause would be that if raw, ok := d.GetOk(tfFieldKey); ok { will only be true when the value is not zero value and zero value can't be set at create time.
It seems that's known issue and can be fixed by migrating to new sdk(terraform-provider-framework) since they have IsNull method to check if not set, or is explicitly set to null.
https://github.com/elastic/terraform-provider-elasticstack/blob/c5e409539eeec2ed46d38eb749ff8d760a9d87d3/internal/utils/utils.go#L148-L163
Workaround would be
- create with value > 0 and update
number_of_replicasto 0 after.
resource "elasticstack_elasticsearch_index" "example" {
name = "example"
number_of_shards = 1
number_of_replicas = 1
}
- use settings field (it's now deprecated though)
resource "elasticstack_elasticsearch_index" "example" {
name = "example"
number_of_shards = 1
settings {
setting {
name = "number_of_replicas"
value = "0"
}
}
}
The root cause would be that
if raw, ok := d.GetOk(tfFieldKey); ok {will only be true when the value is not zero value and zero value can't be set at create time. It seems that's known issue and can be fixed by migrating to new sdk(terraform-provider-framework) since they haveIsNullmethod to check if not set, or is explicitly set to null.https://github.com/elastic/terraform-provider-elasticstack/blob/c5e409539eeec2ed46d38eb749ff8d760a9d87d3/internal/utils/utils.go#L148-L163
Workaround would be
- create with value > 0 and update
number_of_replicasto 0 after.resource "elasticstack_elasticsearch_index" "example" { name = "example" number_of_shards = 1 number_of_replicas = 1 }
- use settings field (it's now deprecated though)
resource "elasticstack_elasticsearch_index" "example" { name = "example" number_of_shards = 1 settings { setting { name = "number_of_replicas" value = "0" } } }
Thank you for your reply!
I ran into this recently - not sure why this bug is closed since it isn't fixed?
I'm seeing this problem with the new version of everything
Requires https://github.com/elastic/terraform-provider-elasticstack/issues/214