Skip to content

Commit

Permalink
Merge pull request #287 from vmware/fix/converter
Browse files Browse the repository at this point in the history
Fix/converter
  • Loading branch information
GilTeraSky authored Oct 11, 2023
2 parents c7cf7b4 + ceb1408 commit 64281f3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
16 changes: 9 additions & 7 deletions internal/helper/converter/construct_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}
}
Expand Down Expand Up @@ -131,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

Expand Down
12 changes: 11 additions & 1 deletion internal/helper/converter/construct_tf_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 64281f3

Please sign in to comment.