Skip to content

Commit 6b65634

Browse files
Improve preview for set elements with computed properties (#3025)
This PR improves the preview displayed for set elements with computed properties in two ways: 1. Fixes hashing of set elements to more closely mimic what TF does - TF never hashes nulls or computed values in set elements, so we adopt their behaviour by using the plugin-sdk `MapFieldReader`. 2. By dropping unknowns when hashing elements we can now correctly match elements from the plan to the state in cases where the resource is replaced. Fixes #3018 Fixes #2779 Related to pulumi/pulumi-aws#5438 Related to pulumi/pulumi-gcp#3142
1 parent cc9a430 commit 6b65634

File tree

166 files changed

+860
-1921
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

166 files changed

+860
-1921
lines changed

pkg/tests/diff_test/testdata/TestSDKv2DetailedDiffSetComputedBlock/block_with_computed_and_nested_force_new/added_end.golden

+1-9
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,6 @@ Plan: 1 to add, 0 to change, 1 to destroy.
5151
[id=id]
5252
[urn=urn:pulumi:test::project::crossprovider:index/testRes:TestRes::example]
5353
~ props: [
54-
~ [0]: {
55-
}
56-
~ [1]: {
57-
}
5854
+ [2]: {
5955
+ nestedProp: "val3"
6056
}
@@ -63,9 +59,5 @@ Resources:
6359
+-1 to replace
6460
1 unchanged
6561
`,
66-
detailedDiff: map[string]interface{}{
67-
"props[0].computed": map[string]interface{}{"kind": "UPDATE"},
68-
"props[1].computed": map[string]interface{}{"kind": "UPDATE"},
69-
"props[2]": map[string]interface{}{"kind": "ADD_REPLACE"},
70-
},
62+
detailedDiff: map[string]interface{}{"props[2]": map[string]interface{}{"kind": "ADD_REPLACE"}},
7163
}

pkg/tests/diff_test/testdata/TestSDKv2DetailedDiffSetComputedBlock/block_with_computed_and_nested_force_new/added_end_unordered.golden

+1-9
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,6 @@ Plan: 1 to add, 0 to change, 1 to destroy.
5151
[id=id]
5252
[urn=urn:pulumi:test::project::crossprovider:index/testRes:TestRes::example]
5353
~ props: [
54-
~ [0]: {
55-
}
56-
~ [1]: {
57-
}
5854
+ [2]: {
5955
+ nestedProp: "val1"
6056
}
@@ -63,9 +59,5 @@ Resources:
6359
+-1 to replace
6460
1 unchanged
6561
`,
66-
detailedDiff: map[string]interface{}{
67-
"props[0].computed": map[string]interface{}{"kind": "UPDATE"},
68-
"props[1].computed": map[string]interface{}{"kind": "UPDATE"},
69-
"props[2]": map[string]interface{}{"kind": "ADD_REPLACE"},
70-
},
62+
detailedDiff: map[string]interface{}{"props[2]": map[string]interface{}{"kind": "ADD_REPLACE"}},
7163
}

pkg/tests/diff_test/testdata/TestSDKv2DetailedDiffSetComputedBlock/block_with_computed_and_nested_force_new/added_front.golden

+3-15
Original file line numberDiff line numberDiff line change
@@ -51,25 +51,13 @@ Plan: 1 to add, 0 to change, 1 to destroy.
5151
[id=id]
5252
[urn=urn:pulumi:test::project::crossprovider:index/testRes:TestRes::example]
5353
~ props: [
54-
~ [0]: {
55-
~ nestedProp: "val2" => "val1"
56-
}
57-
~ [1]: {
58-
~ nestedProp: "val3" => "val2"
59-
}
60-
+ [2]: {
61-
+ nestedProp: "val3"
54+
+ [0]: {
55+
+ nestedProp: "val1"
6256
}
6357
]
6458
Resources:
6559
+-1 to replace
6660
1 unchanged
6761
`,
68-
detailedDiff: map[string]interface{}{
69-
"props[0].computed": map[string]interface{}{"kind": "UPDATE"},
70-
"props[0].nestedProp": map[string]interface{}{"kind": "UPDATE_REPLACE"},
71-
"props[1].computed": map[string]interface{}{"kind": "UPDATE"},
72-
"props[1].nestedProp": map[string]interface{}{"kind": "UPDATE_REPLACE"},
73-
"props[2]": map[string]interface{}{"kind": "ADD_REPLACE"},
74-
},
62+
detailedDiff: map[string]interface{}{"props[0]": map[string]interface{}{"kind": "ADD_REPLACE"}},
7563
}

pkg/tests/diff_test/testdata/TestSDKv2DetailedDiffSetComputedBlock/block_with_computed_and_nested_force_new/added_front_unordered.golden

+3-13
Original file line numberDiff line numberDiff line change
@@ -51,23 +51,13 @@ Plan: 1 to add, 0 to change, 1 to destroy.
5151
[id=id]
5252
[urn=urn:pulumi:test::project::crossprovider:index/testRes:TestRes::example]
5353
~ props: [
54-
~ [0]: {
55-
~ nestedProp: "val1" => "val2"
56-
}
57-
~ [1]: {
58-
}
59-
+ [2]: {
60-
+ nestedProp: "val1"
54+
+ [0]: {
55+
+ nestedProp: "val2"
6156
}
6257
]
6358
Resources:
6459
+-1 to replace
6560
1 unchanged
6661
`,
67-
detailedDiff: map[string]interface{}{
68-
"props[0].computed": map[string]interface{}{"kind": "UPDATE"},
69-
"props[0].nestedProp": map[string]interface{}{"kind": "UPDATE_REPLACE"},
70-
"props[1].computed": map[string]interface{}{"kind": "UPDATE"},
71-
"props[2]": map[string]interface{}{"kind": "ADD_REPLACE"},
72-
},
62+
detailedDiff: map[string]interface{}{"props[0]": map[string]interface{}{"kind": "ADD_REPLACE"}},
7363
}

pkg/tests/diff_test/testdata/TestSDKv2DetailedDiffSetComputedBlock/block_with_computed_and_nested_force_new/added_middle.golden

+3-13
Original file line numberDiff line numberDiff line change
@@ -51,23 +51,13 @@ Plan: 1 to add, 0 to change, 1 to destroy.
5151
[id=id]
5252
[urn=urn:pulumi:test::project::crossprovider:index/testRes:TestRes::example]
5353
~ props: [
54-
~ [0]: {
55-
}
56-
~ [1]: {
57-
~ nestedProp: "val3" => "val2"
58-
}
59-
+ [2]: {
60-
+ nestedProp: "val3"
54+
+ [1]: {
55+
+ nestedProp: "val2"
6156
}
6257
]
6358
Resources:
6459
+-1 to replace
6560
1 unchanged
6661
`,
67-
detailedDiff: map[string]interface{}{
68-
"props[0].computed": map[string]interface{}{"kind": "UPDATE"},
69-
"props[1].computed": map[string]interface{}{"kind": "UPDATE"},
70-
"props[1].nestedProp": map[string]interface{}{"kind": "UPDATE_REPLACE"},
71-
"props[2]": map[string]interface{}{"kind": "ADD_REPLACE"},
72-
},
62+
detailedDiff: map[string]interface{}{"props[1]": map[string]interface{}{"kind": "ADD_REPLACE"}},
7363
}

pkg/tests/diff_test/testdata/TestSDKv2DetailedDiffSetComputedBlock/block_with_computed_and_nested_force_new/added_middle_unordered.golden

+3-15
Original file line numberDiff line numberDiff line change
@@ -51,25 +51,13 @@ Plan: 1 to add, 0 to change, 1 to destroy.
5151
[id=id]
5252
[urn=urn:pulumi:test::project::crossprovider:index/testRes:TestRes::example]
5353
~ props: [
54-
~ [0]: {
55-
~ nestedProp: "val1" => "val2"
56-
}
57-
~ [1]: {
58-
~ nestedProp: "val2" => "val3"
59-
}
60-
+ [2]: {
61-
+ nestedProp: "val1"
54+
+ [1]: {
55+
+ nestedProp: "val3"
6256
}
6357
]
6458
Resources:
6559
+-1 to replace
6660
1 unchanged
6761
`,
68-
detailedDiff: map[string]interface{}{
69-
"props[0].computed": map[string]interface{}{"kind": "UPDATE"},
70-
"props[0].nestedProp": map[string]interface{}{"kind": "UPDATE_REPLACE"},
71-
"props[1].computed": map[string]interface{}{"kind": "UPDATE"},
72-
"props[1].nestedProp": map[string]interface{}{"kind": "UPDATE_REPLACE"},
73-
"props[2]": map[string]interface{}{"kind": "ADD_REPLACE"},
74-
},
62+
detailedDiff: map[string]interface{}{"props[1]": map[string]interface{}{"kind": "ADD_REPLACE"}},
7563
}

pkg/tests/diff_test/testdata/TestSDKv2DetailedDiffSetComputedBlock/block_with_computed_and_nested_force_new/removed_end.golden

+1-9
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,6 @@ Plan: 1 to add, 0 to change, 1 to destroy.
5151
[id=id]
5252
[urn=urn:pulumi:test::project::crossprovider:index/testRes:TestRes::example]
5353
~ props: [
54-
~ [0]: {
55-
}
56-
~ [1]: {
57-
}
5854
- [2]: {
5955
- computed : ""
6056
- nestedProp: "val3"
@@ -64,9 +60,5 @@ Resources:
6460
+-1 to replace
6561
1 unchanged
6662
`,
67-
detailedDiff: map[string]interface{}{
68-
"props[0].computed": map[string]interface{}{"kind": "UPDATE"},
69-
"props[1].computed": map[string]interface{}{"kind": "UPDATE"},
70-
"props[2]": map[string]interface{}{"kind": "DELETE_REPLACE"},
71-
},
63+
detailedDiff: map[string]interface{}{"props[2]": map[string]interface{}{"kind": "DELETE_REPLACE"}},
7264
}

pkg/tests/diff_test/testdata/TestSDKv2DetailedDiffSetComputedBlock/block_with_computed_and_nested_force_new/removed_end_unordered.golden

+3-15
Original file line numberDiff line numberDiff line change
@@ -51,26 +51,14 @@ Plan: 1 to add, 0 to change, 1 to destroy.
5151
[id=id]
5252
[urn=urn:pulumi:test::project::crossprovider:index/testRes:TestRes::example]
5353
~ props: [
54-
~ [0]: {
55-
~ nestedProp: "val1" => "val2"
56-
}
57-
~ [1]: {
58-
~ nestedProp: "val2" => "val3"
59-
}
60-
- [2]: {
54+
- [0]: {
6155
- computed : ""
62-
- nestedProp: "val3"
56+
- nestedProp: "val1"
6357
}
6458
]
6559
Resources:
6660
+-1 to replace
6761
1 unchanged
6862
`,
69-
detailedDiff: map[string]interface{}{
70-
"props[0].computed": map[string]interface{}{"kind": "UPDATE"},
71-
"props[0].nestedProp": map[string]interface{}{"kind": "UPDATE_REPLACE"},
72-
"props[1].computed": map[string]interface{}{"kind": "UPDATE"},
73-
"props[1].nestedProp": map[string]interface{}{"kind": "UPDATE_REPLACE"},
74-
"props[2]": map[string]interface{}{"kind": "DELETE_REPLACE"},
75-
},
63+
detailedDiff: map[string]interface{}{"props[0]": map[string]interface{}{"kind": "DELETE_REPLACE"}},
7664
}

pkg/tests/diff_test/testdata/TestSDKv2DetailedDiffSetComputedBlock/block_with_computed_and_nested_force_new/removed_front.golden

+3-15
Original file line numberDiff line numberDiff line change
@@ -51,26 +51,14 @@ Plan: 1 to add, 0 to change, 1 to destroy.
5151
[id=id]
5252
[urn=urn:pulumi:test::project::crossprovider:index/testRes:TestRes::example]
5353
~ props: [
54-
~ [0]: {
55-
~ nestedProp: "val1" => "val2"
56-
}
57-
~ [1]: {
58-
~ nestedProp: "val2" => "val3"
59-
}
60-
- [2]: {
54+
- [0]: {
6155
- computed : ""
62-
- nestedProp: "val3"
56+
- nestedProp: "val1"
6357
}
6458
]
6559
Resources:
6660
+-1 to replace
6761
1 unchanged
6862
`,
69-
detailedDiff: map[string]interface{}{
70-
"props[0].computed": map[string]interface{}{"kind": "UPDATE"},
71-
"props[0].nestedProp": map[string]interface{}{"kind": "UPDATE_REPLACE"},
72-
"props[1].computed": map[string]interface{}{"kind": "UPDATE"},
73-
"props[1].nestedProp": map[string]interface{}{"kind": "UPDATE_REPLACE"},
74-
"props[2]": map[string]interface{}{"kind": "DELETE_REPLACE"},
75-
},
63+
detailedDiff: map[string]interface{}{"props[0]": map[string]interface{}{"kind": "DELETE_REPLACE"}},
7664
}

pkg/tests/diff_test/testdata/TestSDKv2DetailedDiffSetComputedBlock/block_with_computed_and_nested_force_new/removed_front_unordered.golden

+3-15
Original file line numberDiff line numberDiff line change
@@ -51,26 +51,14 @@ Plan: 1 to add, 0 to change, 1 to destroy.
5151
[id=id]
5252
[urn=urn:pulumi:test::project::crossprovider:index/testRes:TestRes::example]
5353
~ props: [
54-
~ [0]: {
55-
~ nestedProp: "val1" => "val3"
56-
}
57-
~ [1]: {
58-
~ nestedProp: "val2" => "val1"
59-
}
60-
- [2]: {
54+
- [1]: {
6155
- computed : ""
62-
- nestedProp: "val3"
56+
- nestedProp: "val2"
6357
}
6458
]
6559
Resources:
6660
+-1 to replace
6761
1 unchanged
6862
`,
69-
detailedDiff: map[string]interface{}{
70-
"props[0].computed": map[string]interface{}{"kind": "UPDATE"},
71-
"props[0].nestedProp": map[string]interface{}{"kind": "UPDATE_REPLACE"},
72-
"props[1].computed": map[string]interface{}{"kind": "UPDATE"},
73-
"props[1].nestedProp": map[string]interface{}{"kind": "UPDATE_REPLACE"},
74-
"props[2]": map[string]interface{}{"kind": "DELETE_REPLACE"},
75-
},
63+
detailedDiff: map[string]interface{}{"props[1]": map[string]interface{}{"kind": "DELETE_REPLACE"}},
7664
}

pkg/tests/diff_test/testdata/TestSDKv2DetailedDiffSetComputedBlock/block_with_computed_and_nested_force_new/removed_middle.golden

+3-13
Original file line numberDiff line numberDiff line change
@@ -51,24 +51,14 @@ Plan: 1 to add, 0 to change, 1 to destroy.
5151
[id=id]
5252
[urn=urn:pulumi:test::project::crossprovider:index/testRes:TestRes::example]
5353
~ props: [
54-
~ [0]: {
55-
}
56-
~ [1]: {
57-
~ nestedProp: "val2" => "val3"
58-
}
59-
- [2]: {
54+
- [1]: {
6055
- computed : ""
61-
- nestedProp: "val3"
56+
- nestedProp: "val2"
6257
}
6358
]
6459
Resources:
6560
+-1 to replace
6661
1 unchanged
6762
`,
68-
detailedDiff: map[string]interface{}{
69-
"props[0].computed": map[string]interface{}{"kind": "UPDATE"},
70-
"props[1].computed": map[string]interface{}{"kind": "UPDATE"},
71-
"props[1].nestedProp": map[string]interface{}{"kind": "UPDATE_REPLACE"},
72-
"props[2]": map[string]interface{}{"kind": "DELETE_REPLACE"},
73-
},
63+
detailedDiff: map[string]interface{}{"props[1]": map[string]interface{}{"kind": "DELETE_REPLACE"}},
7464
}

pkg/tests/diff_test/testdata/TestSDKv2DetailedDiffSetComputedBlock/block_with_computed_and_nested_force_new/removed_middle_unordered.golden

+3-15
Original file line numberDiff line numberDiff line change
@@ -51,26 +51,14 @@ Plan: 1 to add, 0 to change, 1 to destroy.
5151
[id=id]
5252
[urn=urn:pulumi:test::project::crossprovider:index/testRes:TestRes::example]
5353
~ props: [
54-
~ [0]: {
55-
~ nestedProp: "val1" => "val3"
56-
}
57-
~ [1]: {
58-
~ nestedProp: "val2" => "val1"
59-
}
60-
- [2]: {
54+
- [1]: {
6155
- computed : ""
62-
- nestedProp: "val3"
56+
- nestedProp: "val2"
6357
}
6458
]
6559
Resources:
6660
+-1 to replace
6761
1 unchanged
6862
`,
69-
detailedDiff: map[string]interface{}{
70-
"props[0].computed": map[string]interface{}{"kind": "UPDATE"},
71-
"props[0].nestedProp": map[string]interface{}{"kind": "UPDATE_REPLACE"},
72-
"props[1].computed": map[string]interface{}{"kind": "UPDATE"},
73-
"props[1].nestedProp": map[string]interface{}{"kind": "UPDATE_REPLACE"},
74-
"props[2]": map[string]interface{}{"kind": "DELETE_REPLACE"},
75-
},
63+
detailedDiff: map[string]interface{}{"props[1]": map[string]interface{}{"kind": "DELETE_REPLACE"}},
7664
}

pkg/tests/diff_test/testdata/TestSDKv2DetailedDiffSetComputedBlock/block_with_computed_and_nested_force_new/same_element_updated.golden

-6
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,16 @@ Plan: 1 to add, 0 to change, 1 to destroy.
5656
[id=id]
5757
[urn=urn:pulumi:test::project::crossprovider:index/testRes:TestRes::example]
5858
~ props: [
59-
~ [0]: {
60-
}
6159
~ [1]: {
6260
~ nestedProp: "val2" => "val4"
6361
}
64-
~ [2]: {
65-
}
6662
]
6763
Resources:
6864
+-1 to replace
6965
1 unchanged
7066
`,
7167
detailedDiff: map[string]interface{}{
72-
"props[0].computed": map[string]interface{}{"kind": "UPDATE"},
7368
"props[1].computed": map[string]interface{}{"kind": "UPDATE"},
7469
"props[1].nestedProp": map[string]interface{}{"kind": "UPDATE_REPLACE"},
75-
"props[2].computed": map[string]interface{}{"kind": "UPDATE"},
7670
},
7771
}

pkg/tests/diff_test/testdata/TestSDKv2DetailedDiffSetComputedBlock/block_with_computed_and_nested_force_new/same_element_updated_unordered.golden

+7-13
Original file line numberDiff line numberDiff line change
@@ -56,26 +56,20 @@ Plan: 1 to add, 0 to change, 1 to destroy.
5656
[id=id]
5757
[urn=urn:pulumi:test::project::crossprovider:index/testRes:TestRes::example]
5858
~ props: [
59-
~ [0]: {
60-
~ nestedProp: "val1" => "val2"
59+
+ [1]: {
60+
+ nestedProp: "val4"
6161
}
62-
~ [1]: {
63-
~ nestedProp: "val2" => "val4"
64-
}
65-
~ [2]: {
66-
~ nestedProp: "val3" => "val1"
62+
- [2]: {
63+
- computed : ""
64+
- nestedProp: "val3"
6765
}
6866
]
6967
Resources:
7068
+-1 to replace
7169
1 unchanged
7270
`,
7371
detailedDiff: map[string]interface{}{
74-
"props[0].computed": map[string]interface{}{"kind": "UPDATE"},
75-
"props[0].nestedProp": map[string]interface{}{"kind": "UPDATE_REPLACE"},
76-
"props[1].computed": map[string]interface{}{"kind": "UPDATE"},
77-
"props[1].nestedProp": map[string]interface{}{"kind": "UPDATE_REPLACE"},
78-
"props[2].computed": map[string]interface{}{"kind": "UPDATE"},
79-
"props[2].nestedProp": map[string]interface{}{"kind": "UPDATE_REPLACE"},
72+
"props[1]": map[string]interface{}{"kind": "ADD_REPLACE"},
73+
"props[2]": map[string]interface{}{"kind": "DELETE_REPLACE"},
8074
},
8175
}

0 commit comments

Comments
 (0)