Skip to content

Commit

Permalink
pf resources show diff for empty map
Browse files Browse the repository at this point in the history
re pulumi/pulumi-aws#4080

I've noticed different behavior between sdkv2 and pf resources.
Sometimes if you do not provide a value for a map property it will write
an empty value to the outputs (i.e. `{ "tagsAll": {} }`).

When diff is called, the `olds` show the empty object value and the news
show no entry at all. sdkv2 resources handle this and do not display any
diff whereas pf resources show a diff.
  • Loading branch information
corymhall committed Jul 8, 2024
1 parent f39fe31 commit 9fc9f9e
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
36 changes: 36 additions & 0 deletions pf/tests/provider_diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,39 @@ func TestDiffVersionUpgrade(t *testing.T) {
}`
testutils.Replay(t, server, testCase)
}

// Test shows that an empty object shows a diff if it is not provided
func TestEmptyObjectDiff(t *testing.T) {
server := newProviderServer(t, testprovider.SyntheticTestBridgeProvider())
testCase := `
{
"method": "/pulumirpc.ResourceProvider/Diff",
"request": {
"id": "0",
"urn": "urn:pulumi:test-stack::basicprogram::testbridge:index/testres:Testres::testres1",
"olds": {
"id": "none",
"statedir": "res-461023c",
"requiredInputString": "abc",
"requiredInputStringCopy": "abc",
"optionalInputStringMap": {}
},
"news": {
"statedir": "res-461023c",
"requiredInputString": "abc"
},
"oldInputs": {
"statedir": "res-461023c",
"requiredInputString": "abc"
}
},
"response": {
"changes": "DIFF_SOME",
"diffs": [
"optionalInputStringMap"
]
}
}
`
testutils.Replay(t, server, testCase)
}
49 changes: 49 additions & 0 deletions pkg/tfbridge/tests/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,55 @@ func TestWithNewTestProvider(t *testing.T) {
`)
}

// An empty object does not show a diff if it is not provided
func TestEmptyMapNoDiff(t *testing.T) {
ctx := context.Background()
p := newTestProvider(ctx, tfbridge.ProviderInfo{
P: shimv2.NewProvider(&schema.Provider{
Schema: map[string]*schema.Schema{},
ResourcesMap: map[string]*schema.Resource{
"example_resource": {
Schema: map[string]*schema.Schema{
"optional_input_string_map": {
Type: schema.TypeMap,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Optional: true,
},
},
},
},
}),
Name: "testprov",
ResourcePrefix: "example",
Resources: map[string]*tfbridge.ResourceInfo{
"example_resource": {Tok: "testprov:index:ExampleResource"},
},
}, newTestProviderOptions{})

replay.Replay(t, p, `
{
"method": "/pulumirpc.ResourceProvider/Diff",
"request": {
"id": "0",
"urn": "urn:pulumi:dev::teststack::testprov:index:ExampleResource::exres",
"olds": {
"optionalInputStringMap": {}
},
"news": {
},
"oldInputs": {
}
},
"response": {
"changes": "DIFF_NONE",
"hasDetailedDiff": true
}
}
`)
}

// TestRegress1932 tests that we can have a list with different types (string & unknown)
func TestRegress1932(t *testing.T) {
ctx := context.Background()
Expand Down

0 comments on commit 9fc9f9e

Please sign in to comment.