From 6cebc56fb2b2c314fa47a52c2ede2cd5763e088a 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 --- .vscode/launch.json | 38 +++++++++++++-------- 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 +- 5 files changed, 32 insertions(+), 21 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 1326815..dba518c 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,17 +1,25 @@ { - "version": "0.2.0", - "configurations": [ - { - "name": "Debug Terraform Provider", - "type": "go", - "request": "launch", - "mode": "debug", - // this assumes your workspace is the root of the repo - "program": "${workspaceFolder}", - "env": {}, - "args": [ - "-debug", - ] - } - ] + "version": "0.2.0", + "configurations": [ + { + "name": "Debug Selected Test", + "request": "launch", + "type": "go", + "args": ["-test.v", "-test.run", "^${selectedText}$"], + "mode": "auto", + "program": "${fileDirname}", + "env": { "PKG_NAME": "${relativeFileDirname}" , "TF_ACC": "1" }, + "showLog": true + }, + { + "name": "Debug Terraform Provider", + "type": "go", + "request": "launch", + "mode": "debug", + // this assumes your workspace is the root of the repo + "program": "${workspaceFolder}", + "env": {}, + "args": ["-debug"] + } + ] } 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..7c4e653 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 intValue, ok := value.Value.(float64); ok { + aku = types.Int64Value(int64(intValue)) + } 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 }