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] Cannot create index with number_of_replicas=0 #238

Closed
paivin-dn opened this issue Jan 5, 2023 · 5 comments · Fixed by #698
Closed

[Bug] Cannot create index with number_of_replicas=0 #238

paivin-dn opened this issue Jan 5, 2023 · 5 comments · Fixed by #698
Labels
bug Something isn't working framework-limitation

Comments

@paivin-dn
Copy link

paivin-dn commented Jan 5, 2023

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:

  1. Define index in a terraform code:
resource "elasticstack_elasticsearch_index" "example" {
  name               = "example"
  number_of_shards   = 1
  number_of_replicas = 0
}
  1. Run the terraform plan & terraform plan commands
  2. 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
@paivin-dn paivin-dn added the bug Something isn't working label Jan 5, 2023
@k-yomo
Copy link
Contributor

k-yomo commented Jan 5, 2023

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.

func ExpandIndividuallyDefinedSettings(ctx context.Context, d *schema.ResourceData, settingsKeys map[string]schema.ValueType) map[string]interface{} {
settings := make(map[string]interface{})
for key := range settingsKeys {
tfFieldKey := ConvertSettingsKeyToTFFieldKey(key)
if raw, ok := d.GetOk(tfFieldKey); ok {
switch field := raw.(type) {
case *schema.Set:
settings[key] = field.List()
default:
settings[key] = raw
}
tflog.Trace(ctx, fmt.Sprintf("expandIndividuallyDefinedSettings: settingsKey:%+v tfFieldKey:%+v value:%+v, %+v", key, tfFieldKey, raw, settings))
}
}
return settings
}

Workaround would be

  1. create with value > 0 and update number_of_replicas to 0 after.
resource "elasticstack_elasticsearch_index" "example" {
  name               = "example"
  number_of_shards   = 1
  number_of_replicas = 1
}
  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"
    }
  }
}

@paivin-dn
Copy link
Author

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.

func ExpandIndividuallyDefinedSettings(ctx context.Context, d *schema.ResourceData, settingsKeys map[string]schema.ValueType) map[string]interface{} {
settings := make(map[string]interface{})
for key := range settingsKeys {
tfFieldKey := ConvertSettingsKeyToTFFieldKey(key)
if raw, ok := d.GetOk(tfFieldKey); ok {
switch field := raw.(type) {
case *schema.Set:
settings[key] = field.List()
default:
settings[key] = raw
}
tflog.Trace(ctx, fmt.Sprintf("expandIndividuallyDefinedSettings: settingsKey:%+v tfFieldKey:%+v value:%+v, %+v", key, tfFieldKey, raw, settings))
}
}
return settings
}

Workaround would be

  1. create with value > 0 and update number_of_replicas to 0 after.
resource "elasticstack_elasticsearch_index" "example" {
  name               = "example"
  number_of_shards   = 1
  number_of_replicas = 1
}
  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!

@james-world
Copy link

I ran into this recently - not sure why this bug is closed since it isn't fixed?

@paivin-dn paivin-dn reopened this Feb 10, 2023
@Kushmaro Kushmaro added this to the 0.7.0 milestone Feb 20, 2023
@olfek
Copy link

olfek commented Mar 9, 2023

I'm seeing this problem with the new version of everything

@tobio
Copy link
Member

tobio commented Mar 15, 2023

Requires #214

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working framework-limitation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants