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] SLO resource contains a type mismatch in the optional group_by field #872

Closed
jasonrhodes opened this issue Oct 23, 2024 · 2 comments · Fixed by #878
Closed

[Bug] SLO resource contains a type mismatch in the optional group_by field #872

jasonrhodes opened this issue Oct 23, 2024 · 2 comments · Fixed by #878
Labels
bug Something isn't working

Comments

@jasonrhodes
Copy link
Member

jasonrhodes commented Oct 23, 2024

Describe the bug
The SLO resource defines a "group_by" key whose type is set to string, but the API accepts string OR a list of strings. Because of this, if you edit an SLO using the UI or a direct API call outside of terraform and set it to an array of strings, the terraform provider will fail on subsequent runs.

An example of the error would be:

Error: json: cannot unmarshal array into Go struct field SloResponse.groupBy of type string

  with elasticstack_kibana_slo.slo_task_claim_success_rate["all"],
  on slo-task-claim-success-rate.tf line 1, in resource "elasticstack_kibana_slo" "slo_task_claim_success_rate":
   1: resource "elasticstack_kibana_slo" "slo_task_claim_success_rate" ***


Error: json: cannot unmarshal array into Go struct field SloResponse.groupBy of type string

I intended to submit a PR to update the type, changing the above code to something like this:

		"group_by": {
			Description: "Optional group by field to use to generate an SLO per distinct value.",
			Type:        schema.TypeList,
			Optional:    true,
			ForceNew:    false,
			Elem: &schema.Schema{
				Type: schema.TypeString,
			},
		},

But on reading the docs for schema validation, it doesn't seem to be possible to specify a field that can be EITHER one type OR another, like this one would need to be. I may be missing something, though!

To Reproduce
Steps to reproduce the behavior:

  1. Create an SLO using this provider's SLO resource.
  2. Edit the SLO in the UI, manually add multiple fields to the group by
  3. Run terraform again, you will see an error similar to the above example

Expected behavior
Terraform should handle cases where an SLO has a group_by field set to a single string OR a group_by field set to an array of strings.

Debug output

I don't have access to this, but @jloleysens may be able to provide this.

Versions (please complete the following information):

@jloleysens could you provide these details, also?

  • OS: [e.g. Linux]
  • Terraform Version [e.g. 1.0.0]
  • Provider version [e.g. v0.1.0]
  • Elasticsearch Version [e.g. 7.16.0]

Additional context

None at this time.

@jasonrhodes jasonrhodes added the bug Something isn't working label Oct 23, 2024
@jasonrhodes
Copy link
Member Author

Note: the docs have been recently updated, but the published docs are still not up to date (not sure why, could be a release delay).

The change to allow an array of strings happened in February of 2024.

@tobio
Copy link
Member

tobio commented Oct 24, 2024

Related to #701

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
None yet
Development

Successfully merging a pull request may close this issue.

2 participants