From 92991229eb903eb55aeb798dae981bdfc1735067 Mon Sep 17 00:00:00 2001 From: GilTS Date: Fri, 6 Oct 2023 17:42:12 +0300 Subject: [PATCH 1/3] check if schema value is nil Signed-off-by: GilTS --- internal/helper/converter/construct_model.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/internal/helper/converter/construct_model.go b/internal/helper/converter/construct_model.go index 311560e48..138e688d2 100644 --- a/internal/helper/converter/construct_model.go +++ b/internal/helper/converter/construct_model.go @@ -79,12 +79,14 @@ func modelHandleBlockStructSlice(modelJSON *BlockToStruct, schemaData interface{ for elemMapKey, elemMapValue := range *elemTypeMap { var schemaValue, _ = (schemaData.([]interface{}))[0].(map[string]interface{})[elemMapKey] - if _, ok := elemMapValue.(*ListToStruct); ok { - buildModelField(modelJSON, schemaValue, elemMapValue, arrIndexer) - } else { - for _, item := range schemaValue.([]interface{}) { - buildModelField(modelJSON, []interface{}{item}, elemMapValue, arrIndexer) - arrIndexer.IncrementLastIndex() + if schemaValue != nil { + if _, ok := elemMapValue.(*ListToStruct); ok { + buildModelField(modelJSON, schemaValue, elemMapValue, arrIndexer) + } else { + for _, item := range schemaValue.([]interface{}) { + buildModelField(modelJSON, []interface{}{item}, elemMapValue, arrIndexer) + arrIndexer.IncrementLastIndex() + } } } } From 12117763bf61eb8d34356140afd8b0c8a0779cd8 Mon Sep 17 00:00:00 2001 From: GilTS Date: Fri, 6 Oct 2023 17:42:26 +0300 Subject: [PATCH 2/3] fix err if statement Signed-off-by: GilTS --- internal/helper/converter/construct_tf_schema.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/helper/converter/construct_tf_schema.go b/internal/helper/converter/construct_tf_schema.go index 6d869696f..5136cdfdb 100644 --- a/internal/helper/converter/construct_tf_schema.go +++ b/internal/helper/converter/construct_tf_schema.go @@ -43,7 +43,7 @@ func buildTFValue(modelJSONData *map[string]interface{}, mapValue interface{}, a modelField := mapValue.Field modelValue, err = getModelValue(modelJSONData, modelField, arrIndexer) - if err != nil { + if err == nil { tfSchemaValue = mapValue.EvalFunc(ConstructTFSchema, modelValue) } case string: From ceb1408e1776eed1f7acd7f3096a49d19cd722ea Mon Sep 17 00:00:00 2001 From: GilTS Date: Sun, 8 Oct 2023 22:10:49 +0300 Subject: [PATCH 3/3] Added support for field evaluation in BlockToStructSlice Signed-off-by: GilTS --- internal/helper/converter/construct_model.go | 2 +- internal/helper/converter/construct_tf_schema.go | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/internal/helper/converter/construct_model.go b/internal/helper/converter/construct_model.go index 138e688d2..c5d79ca2e 100644 --- a/internal/helper/converter/construct_model.go +++ b/internal/helper/converter/construct_model.go @@ -133,7 +133,7 @@ func setModelValue(model *BlockToStruct, field string, value interface{}, arrInd } else { fieldPaths := strings.Split(field, ".") arrIndices := arrIndexer.GetAllIndexes() - leafField := fieldPaths[len(fieldPaths)-1] + leafField := strings.ReplaceAll(fieldPaths[len(fieldPaths)-1], "[]", "") arrayFields := 0 parentField := *model diff --git a/internal/helper/converter/construct_tf_schema.go b/internal/helper/converter/construct_tf_schema.go index 5136cdfdb..4628b0595 100644 --- a/internal/helper/converter/construct_tf_schema.go +++ b/internal/helper/converter/construct_tf_schema.go @@ -128,6 +128,16 @@ func tfHandleBlockStructSlice(modelJSONData *map[string]interface{}, mapValue *B } } + isEvaluatedField := false + + for _, v := range *elemMap { + _, isEvaluatedField = v.(*EvaluatedField) + } + + if isEvaluatedField { + break + } + if err == nil { arrIndexer.IncrementLastIndex() } else if err.Error() == arrIndexExceededMsg && i+1 < len(*mapValue) {