I’m getting weird behaviour when I try to flatten Float List -
I defined a list of floats in the schema -
"buckets": schema.ListAttribute{
ElementType: types.Float64Type,
Required: true,
}
and
Buckets types.List
tfsdk:"buckets"
//types.Float64
I flatten the results back to the sate the next way -
func float32SliceTypeList(ctx context.Context, arr []float32) (types.List, diag2.Diagnostics) {
if len(arr) == 0 {
return types.ListNull(types.Float64Type), nil
}
result := make([]attr.Value, 0, len(arr))
for _, v := range arr {
log.Printf("[DEBUG] values - %f, %f", v, float64(v))
result = append(result, types.Float64Value(float64(v)))
}
return types.ListValueFrom(ctx, types.Float64Type, result)
}
and also printed the flatten list to make sure it was flattened correctly -
func flattenE2MHistogramAggregation(ctx context.Context, aggregation *e2m.Aggregation) *HistogramAggregationModel {
if aggregation == nil {
return nil
}
buckets, diags := float32SliceTypeList(ctx, aggregation.GetHistogram().GetBuckets())
if diags.HasError() {
return nil
}
log.Printf("[INFO] Flattened histogram buckets: %v", buckets)
return &HistogramAggregationModel{
Enable: types.BoolValue(aggregation.GetEnabled()),
TargetMetricName: types.StringValue(aggregation.GetTargetMetricName()),
Buckets: buckets,
}
}
I tried to create the next config -
resource "coralogix_events2metric" "xxxxxx"{
...
buckets = [0.1, 0.2, 0.3, 0.5, 1, 2, 3, 5, 10, 20, 30, 50]
}
and saw the values on the flattened list were right -
[INFO] Flattened histogram buckets: [0.100000,0.200000,0.300000,0.500000,1.000000,2.000000,3.000000,5.000000,10.000000,20.000000,30.000000,50.000000]
but then got the next errors -
Error: Provider produced inconsistent result after apply
│
│ When applying changes to coralogix_events2metric.xxxxxx, provider “provider["registry.terraform.io/coralogix/coralogix"]” produced an unexpected new value: .metric_fields[“xxxxxx”].aggregations.histogram.buckets[0]: was
│ cty.MustParseNumberVal(“0.1”), but now cty.NumberFloatVal(0.10000000149011612).
│
│ This is a bug in the provider, which should be reported in the provider’s own issue tracker.
╵
╷
│ Error: Provider produced inconsistent result after apply
│
│ When applying changes to coralogix_events2metric.xxxxxx, provider “provider["registry.terraform.io/coralogix/coralogix"]” produced an unexpected new value: .metric_fields[“xxxxxx”].aggregations.histogram.buckets[1]: was
│ cty.MustParseNumberVal(“0.2”), but now cty.NumberFloatVal(0.20000000298023224).
│
│ This is a bug in the provider, which should be reported in the provider’s own issue tracker.
╵
╷
│ Error: Provider produced inconsistent result after apply
│
│ When applying changes to coralogix_events2metric.xxxxxx, provider “provider["registry.terraform.io/coralogix/coralogix"]” produced an unexpected new value: .metric_fields[“xxxxxx”].aggregations.histogram.buckets[2]: was
│ cty.MustParseNumberVal(“0.3”), but now cty.NumberFloatVal(0.30000001192092896).