From 69904445339c4137dc2389ffc4d001c75c3f2797 Mon Sep 17 00:00:00 2001 From: Gezi-lzq Date: Mon, 21 Oct 2024 19:50:16 +0800 Subject: [PATCH] feat: update Value struct to support different value types --- client/model_kafka_instance.go | 8 ++++---- internal/models/kafka_instance.go | 4 +++- internal/models/kafka_instance_test.go | 1 + internal/provider/resource_instance_test.go | 2 +- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/client/model_kafka_instance.go b/client/model_kafka_instance.go index 0ea9f20..8281ac5 100644 --- a/client/model_kafka_instance.go +++ b/client/model_kafka_instance.go @@ -81,10 +81,10 @@ type PaymentPlan struct { } type Value struct { - Key string `json:"key"` - Name string `json:"name"` - Value int `json:"value"` - DisplayValue string `json:"displayValue"` + Key string `json:"key"` + Name string `json:"name"` + Value interface{} `json:"value"` + DisplayValue string `json:"displayValue"` } type Network struct { diff --git a/internal/models/kafka_instance.go b/internal/models/kafka_instance.go index 01a02ab..c08202a 100644 --- a/internal/models/kafka_instance.go +++ b/internal/models/kafka_instance.go @@ -205,7 +205,9 @@ func flattenComputeSpecs(spec client.Spec) *ComputeSpecsModel { var aku types.Int64 for _, value := range spec.Values { if value.Key == "aku" { - aku = types.Int64Value(int64(value.Value)) + if v, ok := value.Value.(int); ok { + aku = types.Int64Value(int64(v)) + } break } } diff --git a/internal/models/kafka_instance_test.go b/internal/models/kafka_instance_test.go index 9ddf35f..671a467 100644 --- a/internal/models/kafka_instance_test.go +++ b/internal/models/kafka_instance_test.go @@ -21,6 +21,7 @@ func TestFlattenComputeSpecs(t *testing.T) { Version: "1.0.0", Values: []client.Value{ {Key: "aku", Value: 4}, + {Key: "other", Value: "value"}, }, }, expected: ComputeSpecsModel{ diff --git a/internal/provider/resource_instance_test.go b/internal/provider/resource_instance_test.go index d1e0b54..c4bb2b8 100644 --- a/internal/provider/resource_instance_test.go +++ b/internal/provider/resource_instance_test.go @@ -179,7 +179,7 @@ func newInstanceResponse() client.KafkaInstanceResponse { instanceResponse.Spec.PaymentPlan.PaymentType = "ON_DEMAND" instanceResponse.Spec.PaymentPlan.Period = 1 instanceResponse.Spec.PaymentPlan.Unit = "MONTH" - instanceResponse.Spec.Values = []client.Value{{Key: "aku", Value: 6}} + instanceResponse.Spec.Values = []client.Value{{Key: "aku", Value: 6}, {Key: "walMode", Value: "block"}} instanceResponse.Networks = []client.Network{{Zone: "ap-southeast-1a", Subnets: []client.Subnet{{Subnet: "vsw-bp14v5eikr8wrgoqje7hr"}}}} return instanceResponse }