Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions pkg/tfbridge/detailed_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,15 @@ func (differ detailedDiffer) makePropDiff(
return nil
}
propType := differ.getEffectiveType(differ.propertyPathToSchemaPath(path))
if !isPresent(old) || isTypeShapeMismatched(old, propType) {

if isTypeShapeMismatched(old, propType) || isTypeShapeMismatched(new, propType) {
return differ.makePlainPropDiff(path, old, new)
}

if !isPresent(old) {
old = resource.NewNullProperty()
}
if !new.IsComputed() && (!isPresent(new) || isTypeShapeMismatched(new, propType)) {
if !new.IsComputed() && !isPresent(new) {
new = resource.NewNullProperty()
}
if old.IsNull() || new.IsNull() || new.IsComputed() {
Expand Down
113 changes: 113 additions & 0 deletions pkg/tfbridge/detailed_diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1747,3 +1747,116 @@ func TestDetailedDiffPulumiSchemaOverride(t *testing.T) {
})
})
}

func TestDetailedDiffMismatchedSchemas(t *testing.T) {
stringSchema := map[string]*schema.Schema{
"foo": {
Type: schema.TypeString,
Optional: true,
},
}

listSchema := map[string]*schema.Schema{
"foo": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
}

setSchema := map[string]*schema.Schema{
"foo": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
}

mapSchema := map[string]*schema.Schema{
"foo": {
Type: schema.TypeMap,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
}

stringValue := resource.NewPropertyMapFromMap(
map[string]interface{}{
"foo": "string-value",
},
)

listValue := resource.NewPropertyMapFromMap(
map[string]interface{}{
"foo": []interface{}{"list-value"},
},
)

mapValue := resource.NewPropertyMapFromMap(
map[string]interface{}{
"foo": map[string]interface{}{"bar": "map-value"},
},
)

t.Run("list schema with string value", func(t *testing.T) {
tfs := shimv2.NewSchemaMap(listSchema)
runDetailedDiffTest(t, stringValue, listValue, tfs, nil, map[string]*pulumirpc.PropertyDiff{
"foo": {Kind: pulumirpc.PropertyDiff_UPDATE},
})
})

t.Run("list schema with map value", func(t *testing.T) {
tfs := shimv2.NewSchemaMap(listSchema)
runDetailedDiffTest(t, mapValue, listValue, tfs, nil, map[string]*pulumirpc.PropertyDiff{
"foo": {Kind: pulumirpc.PropertyDiff_UPDATE},
})
})

t.Run("set schema with string value", func(t *testing.T) {
tfs := shimv2.NewSchemaMap(setSchema)
runDetailedDiffTest(t, stringValue, listValue, tfs, nil, map[string]*pulumirpc.PropertyDiff{
"foo": {Kind: pulumirpc.PropertyDiff_UPDATE},
})
})

t.Run("set schema with map value", func(t *testing.T) {
tfs := shimv2.NewSchemaMap(setSchema)
runDetailedDiffTest(t, mapValue, listValue, tfs, nil, map[string]*pulumirpc.PropertyDiff{
"foo": {Kind: pulumirpc.PropertyDiff_UPDATE},
})
})

t.Run("string schema with list value", func(t *testing.T) {
tfs := shimv2.NewSchemaMap(stringSchema)
runDetailedDiffTest(t, listValue, stringValue, tfs, nil, map[string]*pulumirpc.PropertyDiff{
"foo": {Kind: pulumirpc.PropertyDiff_UPDATE},
})
})

t.Run("string schema with map value", func(t *testing.T) {
tfs := shimv2.NewSchemaMap(stringSchema)
runDetailedDiffTest(t, mapValue, stringValue, tfs, nil, map[string]*pulumirpc.PropertyDiff{
"foo": {Kind: pulumirpc.PropertyDiff_UPDATE},
})
})

t.Run("map schema with string value", func(t *testing.T) {
tfs := shimv2.NewSchemaMap(mapSchema)
runDetailedDiffTest(t, stringValue, mapValue, tfs, nil, map[string]*pulumirpc.PropertyDiff{
"foo": {Kind: pulumirpc.PropertyDiff_UPDATE},
})
})

t.Run("map schema with list value", func(t *testing.T) {
tfs := shimv2.NewSchemaMap(mapSchema)
runDetailedDiffTest(t, listValue, mapValue, tfs, nil, map[string]*pulumirpc.PropertyDiff{
"foo": {Kind: pulumirpc.PropertyDiff_UPDATE},
})
})
}
Loading