Description
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:
- Create an SLO using this provider's SLO resource.
- Edit the SLO in the UI, manually add multiple fields to the group by
- 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.