pulumi/pkg/engine/detailedDiff_test.go

741 lines
18 KiB
Go
Raw Permalink Normal View History

package engine
Defer all diffs to resource providers. (#2849) Thse changes make a subtle but critical adjustment to the process the Pulumi engine uses to determine whether or not a difference exists between a resource's actual and desired states, and adjusts the way this difference is calculated and displayed accordingly. Today, the Pulumi engine get the first chance to decide whether or not there is a difference between a resource's actual and desired states. It does this by comparing the current set of inputs for a resource (i.e. the inputs from the running Pulumi program) with the last set of inputs used to update the resource. If there is no difference between the old and new inputs, the engine decides that no change is necessary without consulting the resource's provider. Only if there are changes does the engine consult the resource's provider for more information about the difference. This can be problematic for a number of reasons: - Not all providers do input-input comparison; some do input-state comparison - Not all providers are able to update the last deployed set of inputs when performing a refresh - Some providers--either intentionally or due to bugs--may see changes in resources whose inputs have not changed All of these situations are confusing at the very least, and the first is problematic with respect to correctness. Furthermore, the display code only renders diffs it observes rather than rendering the diffs observed by the provider, which can obscure the actual changes detected at runtime. These changes address both of these issues: - Rather than comparing the current inputs against the last inputs before calling a resource provider's Diff function, the engine calls the Diff function in all cases. - Providers may now return a list of properties that differ between the requested and actual state and the way in which they differ. This information will then be used by the CLI to render the diff appropriately. A provider may also indicate that a particular diff is between old and new inputs rather than old state and new inputs. Fixes #2453.
2019-07-01 19:34:19 +00:00
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/pulumi/pulumi/sdk/v3/go/common/resource"
"github.com/pulumi/pulumi/sdk/v3/go/common/resource/plugin"
Defer all diffs to resource providers. (#2849) Thse changes make a subtle but critical adjustment to the process the Pulumi engine uses to determine whether or not a difference exists between a resource's actual and desired states, and adjusts the way this difference is calculated and displayed accordingly. Today, the Pulumi engine get the first chance to decide whether or not there is a difference between a resource's actual and desired states. It does this by comparing the current set of inputs for a resource (i.e. the inputs from the running Pulumi program) with the last set of inputs used to update the resource. If there is no difference between the old and new inputs, the engine decides that no change is necessary without consulting the resource's provider. Only if there are changes does the engine consult the resource's provider for more information about the difference. This can be problematic for a number of reasons: - Not all providers do input-input comparison; some do input-state comparison - Not all providers are able to update the last deployed set of inputs when performing a refresh - Some providers--either intentionally or due to bugs--may see changes in resources whose inputs have not changed All of these situations are confusing at the very least, and the first is problematic with respect to correctness. Furthermore, the display code only renders diffs it observes rather than rendering the diffs observed by the provider, which can obscure the actual changes detected at runtime. These changes address both of these issues: - Rather than comparing the current inputs against the last inputs before calling a resource provider's Diff function, the engine calls the Diff function in all cases. - Providers may now return a list of properties that differ between the requested and actual state and the way in which they differ. This information will then be used by the CLI to render the diff appropriately. A provider may also indicate that a particular diff is between old and new inputs rather than old state and new inputs. Fixes #2453.
2019-07-01 19:34:19 +00:00
)
func TestTranslateDetailedDiff(t *testing.T) {
t.Parallel()
Defer all diffs to resource providers. (#2849) Thse changes make a subtle but critical adjustment to the process the Pulumi engine uses to determine whether or not a difference exists between a resource's actual and desired states, and adjusts the way this difference is calculated and displayed accordingly. Today, the Pulumi engine get the first chance to decide whether or not there is a difference between a resource's actual and desired states. It does this by comparing the current set of inputs for a resource (i.e. the inputs from the running Pulumi program) with the last set of inputs used to update the resource. If there is no difference between the old and new inputs, the engine decides that no change is necessary without consulting the resource's provider. Only if there are changes does the engine consult the resource's provider for more information about the difference. This can be problematic for a number of reasons: - Not all providers do input-input comparison; some do input-state comparison - Not all providers are able to update the last deployed set of inputs when performing a refresh - Some providers--either intentionally or due to bugs--may see changes in resources whose inputs have not changed All of these situations are confusing at the very least, and the first is problematic with respect to correctness. Furthermore, the display code only renders diffs it observes rather than rendering the diffs observed by the provider, which can obscure the actual changes detected at runtime. These changes address both of these issues: - Rather than comparing the current inputs against the last inputs before calling a resource provider's Diff function, the engine calls the Diff function in all cases. - Providers may now return a list of properties that differ between the requested and actual state and the way in which they differ. This information will then be used by the CLI to render the diff appropriately. A provider may also indicate that a particular diff is between old and new inputs rather than old state and new inputs. Fixes #2453.
2019-07-01 19:34:19 +00:00
var (
A = plugin.PropertyDiff{Kind: plugin.DiffAdd}
D = plugin.PropertyDiff{Kind: plugin.DiffDelete}
U = plugin.PropertyDiff{Kind: plugin.DiffUpdate}
)
cases := []struct {
state map[string]interface{}
oldInputs map[string]interface{}
inputs map[string]interface{}
detailedDiff map[string]plugin.PropertyDiff
expected *resource.ObjectDiff
}{
{
state: map[string]interface{}{
"foo": 42,
},
inputs: map[string]interface{}{
"foo": 24,
},
detailedDiff: map[string]plugin.PropertyDiff{
"foo": U,
},
expected: &resource.ObjectDiff{
Adds: resource.PropertyMap{},
Deletes: resource.PropertyMap{},
Sames: resource.PropertyMap{},
Updates: map[resource.PropertyKey]resource.ValueDiff{
"foo": {
Old: resource.NewNumberProperty(42),
New: resource.NewNumberProperty(24),
},
},
},
},
{
state: map[string]interface{}{
"foo": 42,
},
inputs: map[string]interface{}{
"foo": 42,
},
detailedDiff: map[string]plugin.PropertyDiff{
"foo": U,
},
expected: &resource.ObjectDiff{
Adds: resource.PropertyMap{},
Deletes: resource.PropertyMap{},
Sames: resource.PropertyMap{},
Updates: map[resource.PropertyKey]resource.ValueDiff{
"foo": {
Old: resource.NewNumberProperty(42),
New: resource.NewNumberProperty(42),
},
},
},
},
{
state: map[string]interface{}{
"foo": 42,
"bar": "hello",
},
inputs: map[string]interface{}{
"foo": 24,
"bar": "hello",
},
detailedDiff: map[string]plugin.PropertyDiff{
"foo": U,
},
expected: &resource.ObjectDiff{
Adds: resource.PropertyMap{},
Deletes: resource.PropertyMap{},
Sames: resource.PropertyMap{},
Updates: map[resource.PropertyKey]resource.ValueDiff{
"foo": {
Old: resource.NewNumberProperty(42),
New: resource.NewNumberProperty(24),
},
},
},
},
{
state: map[string]interface{}{
"foo": 42,
"bar": "hello",
},
inputs: map[string]interface{}{
"foo": 24,
"bar": "world",
},
detailedDiff: map[string]plugin.PropertyDiff{
"foo": U,
},
expected: &resource.ObjectDiff{
Adds: resource.PropertyMap{},
Deletes: resource.PropertyMap{},
Sames: resource.PropertyMap{},
Updates: map[resource.PropertyKey]resource.ValueDiff{
"foo": {
Old: resource.NewNumberProperty(42),
New: resource.NewNumberProperty(24),
},
},
},
},
{
state: map[string]interface{}{},
inputs: map[string]interface{}{
"foo": 24,
},
detailedDiff: map[string]plugin.PropertyDiff{
"foo": A,
},
expected: &resource.ObjectDiff{
Adds: resource.PropertyMap{
"foo": resource.NewNumberProperty(24),
},
Deletes: resource.PropertyMap{},
Sames: resource.PropertyMap{},
Updates: map[resource.PropertyKey]resource.ValueDiff{},
},
},
{
state: map[string]interface{}{
"foo": 24,
},
inputs: map[string]interface{}{},
detailedDiff: map[string]plugin.PropertyDiff{
"foo": D,
},
expected: &resource.ObjectDiff{
Adds: resource.PropertyMap{},
Deletes: resource.PropertyMap{
"foo": resource.NewNumberProperty(24),
},
Sames: resource.PropertyMap{},
Updates: map[resource.PropertyKey]resource.ValueDiff{},
},
},
{
state: map[string]interface{}{
"foo": 24,
},
oldInputs: map[string]interface{}{
"foo": 42,
},
inputs: map[string]interface{}{},
detailedDiff: map[string]plugin.PropertyDiff{
"foo": {
Kind: plugin.DiffDelete,
InputDiff: true,
},
},
expected: &resource.ObjectDiff{
Adds: resource.PropertyMap{},
Deletes: resource.PropertyMap{
"foo": resource.NewNumberProperty(42),
},
Sames: resource.PropertyMap{},
Updates: map[resource.PropertyKey]resource.ValueDiff{},
},
},
{
state: map[string]interface{}{
"foo": []interface{}{
"bar",
"baz",
},
},
inputs: map[string]interface{}{
"foo": []interface{}{
"bar",
"qux",
},
},
detailedDiff: map[string]plugin.PropertyDiff{
"foo[1]": U,
},
expected: &resource.ObjectDiff{
Adds: resource.PropertyMap{},
Deletes: resource.PropertyMap{},
Sames: resource.PropertyMap{},
Updates: map[resource.PropertyKey]resource.ValueDiff{
"foo": {
Array: &resource.ArrayDiff{
Adds: map[int]resource.PropertyValue{},
Deletes: map[int]resource.PropertyValue{},
Sames: map[int]resource.PropertyValue{},
Updates: map[int]resource.ValueDiff{
1: {
Old: resource.NewStringProperty("baz"),
New: resource.NewStringProperty("qux"),
},
},
},
},
},
},
},
{
state: map[string]interface{}{
"foo": []interface{}{
"bar",
"baz",
},
},
inputs: map[string]interface{}{
"foo": []interface{}{
"bar",
"qux",
},
},
detailedDiff: map[string]plugin.PropertyDiff{
"foo": U,
},
expected: &resource.ObjectDiff{
Adds: resource.PropertyMap{},
Deletes: resource.PropertyMap{},
Sames: resource.PropertyMap{},
Updates: map[resource.PropertyKey]resource.ValueDiff{
"foo": {
Old: resource.NewPropertyValue([]interface{}{
"bar",
"baz",
}),
New: resource.NewPropertyValue([]interface{}{
"bar",
"qux",
}),
Array: &resource.ArrayDiff{
Adds: map[int]resource.PropertyValue{},
Deletes: map[int]resource.PropertyValue{},
Sames: map[int]resource.PropertyValue{
0: resource.NewPropertyValue("bar"),
},
Updates: map[int]resource.ValueDiff{
1: {
Old: resource.NewStringProperty("baz"),
New: resource.NewStringProperty("qux"),
},
},
},
},
},
},
},
Defer all diffs to resource providers. (#2849) Thse changes make a subtle but critical adjustment to the process the Pulumi engine uses to determine whether or not a difference exists between a resource's actual and desired states, and adjusts the way this difference is calculated and displayed accordingly. Today, the Pulumi engine get the first chance to decide whether or not there is a difference between a resource's actual and desired states. It does this by comparing the current set of inputs for a resource (i.e. the inputs from the running Pulumi program) with the last set of inputs used to update the resource. If there is no difference between the old and new inputs, the engine decides that no change is necessary without consulting the resource's provider. Only if there are changes does the engine consult the resource's provider for more information about the difference. This can be problematic for a number of reasons: - Not all providers do input-input comparison; some do input-state comparison - Not all providers are able to update the last deployed set of inputs when performing a refresh - Some providers--either intentionally or due to bugs--may see changes in resources whose inputs have not changed All of these situations are confusing at the very least, and the first is problematic with respect to correctness. Furthermore, the display code only renders diffs it observes rather than rendering the diffs observed by the provider, which can obscure the actual changes detected at runtime. These changes address both of these issues: - Rather than comparing the current inputs against the last inputs before calling a resource provider's Diff function, the engine calls the Diff function in all cases. - Providers may now return a list of properties that differ between the requested and actual state and the way in which they differ. This information will then be used by the CLI to render the diff appropriately. A provider may also indicate that a particular diff is between old and new inputs rather than old state and new inputs. Fixes #2453.
2019-07-01 19:34:19 +00:00
{
state: map[string]interface{}{
"foo": []interface{}{
"bar",
},
},
inputs: map[string]interface{}{
"foo": []interface{}{
"bar",
"baz",
},
},
detailedDiff: map[string]plugin.PropertyDiff{
"foo[1]": A,
},
expected: &resource.ObjectDiff{
Adds: resource.PropertyMap{},
Deletes: resource.PropertyMap{},
Sames: resource.PropertyMap{},
Updates: map[resource.PropertyKey]resource.ValueDiff{
"foo": {
Array: &resource.ArrayDiff{
Adds: map[int]resource.PropertyValue{
1: resource.NewStringProperty("baz"),
},
Deletes: map[int]resource.PropertyValue{},
Sames: map[int]resource.PropertyValue{},
Updates: map[int]resource.ValueDiff{},
},
},
},
},
},
{
state: map[string]interface{}{
"foo": []interface{}{
"bar",
"baz",
},
},
inputs: map[string]interface{}{
"foo": []interface{}{
"bar",
},
},
detailedDiff: map[string]plugin.PropertyDiff{
"foo[1]": D,
},
expected: &resource.ObjectDiff{
Adds: resource.PropertyMap{},
Deletes: resource.PropertyMap{},
Sames: resource.PropertyMap{},
Updates: map[resource.PropertyKey]resource.ValueDiff{
"foo": {
Array: &resource.ArrayDiff{
Adds: map[int]resource.PropertyValue{},
Deletes: map[int]resource.PropertyValue{
1: resource.NewStringProperty("baz"),
},
Sames: map[int]resource.PropertyValue{},
Updates: map[int]resource.ValueDiff{},
},
},
},
},
},
{
state: map[string]interface{}{
"foo": []interface{}{
"bar",
"baz",
},
},
inputs: map[string]interface{}{
"foo": []interface{}{
"bar",
"qux",
},
},
detailedDiff: map[string]plugin.PropertyDiff{
"foo[100]": U,
},
expected: &resource.ObjectDiff{
Adds: resource.PropertyMap{},
Deletes: resource.PropertyMap{},
Sames: resource.PropertyMap{},
Updates: map[resource.PropertyKey]resource.ValueDiff{
"foo": {
Array: &resource.ArrayDiff{
Adds: map[int]resource.PropertyValue{},
Deletes: map[int]resource.PropertyValue{},
Sames: map[int]resource.PropertyValue{},
Updates: map[int]resource.ValueDiff{
100: {
Old: resource.PropertyValue{},
New: resource.PropertyValue{},
},
},
},
},
},
},
},
{
state: map[string]interface{}{
"foo": []interface{}{
"bar",
"baz",
},
},
inputs: map[string]interface{}{
"foo": []interface{}{
"bar",
"qux",
},
},
detailedDiff: map[string]plugin.PropertyDiff{
"foo[100][200]": U,
},
expected: &resource.ObjectDiff{
Adds: resource.PropertyMap{},
Deletes: resource.PropertyMap{},
Sames: resource.PropertyMap{},
Updates: map[resource.PropertyKey]resource.ValueDiff{
"foo": {
Array: &resource.ArrayDiff{
Adds: map[int]resource.PropertyValue{},
Deletes: map[int]resource.PropertyValue{},
Sames: map[int]resource.PropertyValue{},
Updates: map[int]resource.ValueDiff{
100: {
Array: &resource.ArrayDiff{
Adds: map[int]resource.PropertyValue{},
Deletes: map[int]resource.PropertyValue{},
Sames: map[int]resource.PropertyValue{},
Updates: map[int]resource.ValueDiff{
200: {
Old: resource.PropertyValue{},
New: resource.PropertyValue{},
},
},
},
},
},
},
},
},
},
},
{
state: map[string]interface{}{
"foo": []interface{}{
map[string]interface{}{
"baz": 42,
},
},
},
inputs: map[string]interface{}{
"foo": []interface{}{},
},
detailedDiff: map[string]plugin.PropertyDiff{
"foo[0].baz": D,
},
expected: &resource.ObjectDiff{
Adds: resource.PropertyMap{},
Deletes: resource.PropertyMap{},
Sames: resource.PropertyMap{},
Updates: map[resource.PropertyKey]resource.ValueDiff{
"foo": {
Array: &resource.ArrayDiff{
Adds: map[int]resource.PropertyValue{},
Deletes: map[int]resource.PropertyValue{
0: resource.NewObjectProperty(resource.PropertyMap{
"baz": resource.NewNumberProperty(42),
}),
},
Sames: map[int]resource.PropertyValue{},
Updates: map[int]resource.ValueDiff{},
},
},
},
},
},
{
state: map[string]interface{}{
"foo": map[string]interface{}{
"bar": "baz",
"qux": "zed",
},
},
inputs: map[string]interface{}{
"foo": map[string]interface{}{
"bar": "baz",
"qux": "alpha",
},
},
detailedDiff: map[string]plugin.PropertyDiff{
"foo.qux": U,
},
expected: &resource.ObjectDiff{
Adds: resource.PropertyMap{},
Deletes: resource.PropertyMap{},
Sames: resource.PropertyMap{},
Updates: map[resource.PropertyKey]resource.ValueDiff{
"foo": {
Object: &resource.ObjectDiff{
Adds: resource.PropertyMap{},
Deletes: resource.PropertyMap{},
Sames: resource.PropertyMap{},
Updates: map[resource.PropertyKey]resource.ValueDiff{
"qux": {
Old: resource.NewStringProperty("zed"),
New: resource.NewStringProperty("alpha"),
},
},
},
},
},
},
},
{
state: map[string]interface{}{
"foo": map[string]interface{}{
"bar": "baz",
"qux": "zed",
},
},
inputs: map[string]interface{}{
"foo": map[string]interface{}{
"bar": "baz",
"qux": "alpha",
},
},
detailedDiff: map[string]plugin.PropertyDiff{
"foo": U,
},
expected: &resource.ObjectDiff{
Adds: resource.PropertyMap{},
Deletes: resource.PropertyMap{},
Sames: resource.PropertyMap{},
Updates: map[resource.PropertyKey]resource.ValueDiff{
"foo": {
Old: resource.NewPropertyValue(map[string]interface{}{
"bar": "baz",
"qux": "zed",
}),
New: resource.NewPropertyValue(map[string]interface{}{
"bar": "baz",
"qux": "alpha",
}),
Object: &resource.ObjectDiff{
Adds: resource.PropertyMap{},
Deletes: resource.PropertyMap{},
Sames: resource.PropertyMap{
"bar": resource.NewPropertyValue("baz"),
},
Updates: map[resource.PropertyKey]resource.ValueDiff{
"qux": {
Old: resource.NewStringProperty("zed"),
New: resource.NewStringProperty("alpha"),
},
},
},
},
},
},
},
Defer all diffs to resource providers. (#2849) Thse changes make a subtle but critical adjustment to the process the Pulumi engine uses to determine whether or not a difference exists between a resource's actual and desired states, and adjusts the way this difference is calculated and displayed accordingly. Today, the Pulumi engine get the first chance to decide whether or not there is a difference between a resource's actual and desired states. It does this by comparing the current set of inputs for a resource (i.e. the inputs from the running Pulumi program) with the last set of inputs used to update the resource. If there is no difference between the old and new inputs, the engine decides that no change is necessary without consulting the resource's provider. Only if there are changes does the engine consult the resource's provider for more information about the difference. This can be problematic for a number of reasons: - Not all providers do input-input comparison; some do input-state comparison - Not all providers are able to update the last deployed set of inputs when performing a refresh - Some providers--either intentionally or due to bugs--may see changes in resources whose inputs have not changed All of these situations are confusing at the very least, and the first is problematic with respect to correctness. Furthermore, the display code only renders diffs it observes rather than rendering the diffs observed by the provider, which can obscure the actual changes detected at runtime. These changes address both of these issues: - Rather than comparing the current inputs against the last inputs before calling a resource provider's Diff function, the engine calls the Diff function in all cases. - Providers may now return a list of properties that differ between the requested and actual state and the way in which they differ. This information will then be used by the CLI to render the diff appropriately. A provider may also indicate that a particular diff is between old and new inputs rather than old state and new inputs. Fixes #2453.
2019-07-01 19:34:19 +00:00
{
state: map[string]interface{}{
"foo": map[string]interface{}{
"bar": "baz",
},
},
inputs: map[string]interface{}{
"foo": map[string]interface{}{
"bar": "baz",
"qux": "alpha",
},
},
detailedDiff: map[string]plugin.PropertyDiff{
"foo.qux": A,
},
expected: &resource.ObjectDiff{
Adds: resource.PropertyMap{},
Deletes: resource.PropertyMap{},
Sames: resource.PropertyMap{},
Updates: map[resource.PropertyKey]resource.ValueDiff{
"foo": {
Object: &resource.ObjectDiff{
Adds: resource.PropertyMap{
"qux": resource.NewStringProperty("alpha"),
},
Deletes: resource.PropertyMap{},
Sames: resource.PropertyMap{},
Updates: map[resource.PropertyKey]resource.ValueDiff{},
},
},
},
},
},
{
state: map[string]interface{}{
"foo": map[string]interface{}{
"bar": "baz",
"qux": "zed",
},
},
inputs: map[string]interface{}{
"foo": map[string]interface{}{
"bar": "baz",
},
},
detailedDiff: map[string]plugin.PropertyDiff{
"foo.qux": D,
},
expected: &resource.ObjectDiff{
Adds: resource.PropertyMap{},
Deletes: resource.PropertyMap{},
Sames: resource.PropertyMap{},
Updates: map[resource.PropertyKey]resource.ValueDiff{
"foo": {
Object: &resource.ObjectDiff{
Adds: resource.PropertyMap{},
Deletes: resource.PropertyMap{
"qux": resource.NewStringProperty("zed"),
},
Sames: resource.PropertyMap{},
Updates: map[resource.PropertyKey]resource.ValueDiff{},
},
},
},
},
},
{
state: map[string]interface{}{
"foo": map[string]interface{}{
"bar": "baz",
"qux": "zed",
},
},
inputs: map[string]interface{}{
"foo": map[string]interface{}{
"bar": "baz",
"qux": "alpha",
},
},
detailedDiff: map[string]plugin.PropertyDiff{
"foo.missing": U,
},
expected: &resource.ObjectDiff{
Adds: resource.PropertyMap{},
Deletes: resource.PropertyMap{},
Sames: resource.PropertyMap{},
Updates: map[resource.PropertyKey]resource.ValueDiff{
"foo": {
Object: &resource.ObjectDiff{
Adds: resource.PropertyMap{},
Deletes: resource.PropertyMap{},
Sames: resource.PropertyMap{},
Updates: map[resource.PropertyKey]resource.ValueDiff{
"missing": {
Old: resource.PropertyValue{},
New: resource.PropertyValue{},
},
},
},
},
},
},
},
{
state: map[string]interface{}{
"foo": map[string]interface{}{
"bar": "baz",
"qux": "zed",
},
},
inputs: map[string]interface{}{
"foo": map[string]interface{}{
"bar": "baz",
"qux": "alpha",
},
},
detailedDiff: map[string]plugin.PropertyDiff{
"foo.nested.missing": U,
},
expected: &resource.ObjectDiff{
Adds: resource.PropertyMap{},
Deletes: resource.PropertyMap{},
Sames: resource.PropertyMap{},
Updates: map[resource.PropertyKey]resource.ValueDiff{
"foo": {
Object: &resource.ObjectDiff{
Adds: resource.PropertyMap{},
Deletes: resource.PropertyMap{},
Sames: resource.PropertyMap{},
Updates: map[resource.PropertyKey]resource.ValueDiff{
"nested": {
Object: &resource.ObjectDiff{
Adds: resource.PropertyMap{},
Deletes: resource.PropertyMap{},
Sames: resource.PropertyMap{},
Updates: map[resource.PropertyKey]resource.ValueDiff{
"missing": {
Old: resource.PropertyValue{},
New: resource.PropertyValue{},
},
},
},
},
},
},
},
},
},
},
{
state: map[string]interface{}{
"foo": []interface{}{
map[string]interface{}{
"baz": 42,
},
},
},
inputs: map[string]interface{}{
"foo": []interface{}{},
},
detailedDiff: map[string]plugin.PropertyDiff{
"foo[0].baz": D,
},
expected: &resource.ObjectDiff{
Adds: resource.PropertyMap{},
Deletes: resource.PropertyMap{},
Sames: resource.PropertyMap{},
Updates: map[resource.PropertyKey]resource.ValueDiff{
"foo": {
Array: &resource.ArrayDiff{
Adds: map[int]resource.PropertyValue{},
Deletes: map[int]resource.PropertyValue{
0: resource.NewObjectProperty(resource.PropertyMap{
"baz": resource.NewNumberProperty(42),
}),
},
Sames: map[int]resource.PropertyValue{},
Updates: map[int]resource.ValueDiff{},
},
},
},
},
},
{
state: map[string]interface{}{},
inputs: map[string]interface{}{},
detailedDiff: map[string]plugin.PropertyDiff{
"foo[something.wonky]probably/miscalculated.by.provider": U,
},
expected: &resource.ObjectDiff{
Adds: resource.PropertyMap{},
Deletes: resource.PropertyMap{},
Sames: resource.PropertyMap{},
Updates: map[resource.PropertyKey]resource.ValueDiff{
"foo[something.wonky]probably/miscalculated.by.provider": {},
},
},
},
Defer all diffs to resource providers. (#2849) Thse changes make a subtle but critical adjustment to the process the Pulumi engine uses to determine whether or not a difference exists between a resource's actual and desired states, and adjusts the way this difference is calculated and displayed accordingly. Today, the Pulumi engine get the first chance to decide whether or not there is a difference between a resource's actual and desired states. It does this by comparing the current set of inputs for a resource (i.e. the inputs from the running Pulumi program) with the last set of inputs used to update the resource. If there is no difference between the old and new inputs, the engine decides that no change is necessary without consulting the resource's provider. Only if there are changes does the engine consult the resource's provider for more information about the difference. This can be problematic for a number of reasons: - Not all providers do input-input comparison; some do input-state comparison - Not all providers are able to update the last deployed set of inputs when performing a refresh - Some providers--either intentionally or due to bugs--may see changes in resources whose inputs have not changed All of these situations are confusing at the very least, and the first is problematic with respect to correctness. Furthermore, the display code only renders diffs it observes rather than rendering the diffs observed by the provider, which can obscure the actual changes detected at runtime. These changes address both of these issues: - Rather than comparing the current inputs against the last inputs before calling a resource provider's Diff function, the engine calls the Diff function in all cases. - Providers may now return a list of properties that differ between the requested and actual state and the way in which they differ. This information will then be used by the CLI to render the diff appropriately. A provider may also indicate that a particular diff is between old and new inputs rather than old state and new inputs. Fixes #2453.
2019-07-01 19:34:19 +00:00
}
for _, c := range cases {
oldInputs := resource.NewPropertyMapFromMap(c.oldInputs)
state := resource.NewPropertyMapFromMap(c.state)
inputs := resource.NewPropertyMapFromMap(c.inputs)
diff := TranslateDetailedDiff(&StepEventMetadata{
Old: &StepEventStateMetadata{Inputs: oldInputs, Outputs: state},
New: &StepEventStateMetadata{Inputs: inputs},
Defer all diffs to resource providers. (#2849) Thse changes make a subtle but critical adjustment to the process the Pulumi engine uses to determine whether or not a difference exists between a resource's actual and desired states, and adjusts the way this difference is calculated and displayed accordingly. Today, the Pulumi engine get the first chance to decide whether or not there is a difference between a resource's actual and desired states. It does this by comparing the current set of inputs for a resource (i.e. the inputs from the running Pulumi program) with the last set of inputs used to update the resource. If there is no difference between the old and new inputs, the engine decides that no change is necessary without consulting the resource's provider. Only if there are changes does the engine consult the resource's provider for more information about the difference. This can be problematic for a number of reasons: - Not all providers do input-input comparison; some do input-state comparison - Not all providers are able to update the last deployed set of inputs when performing a refresh - Some providers--either intentionally or due to bugs--may see changes in resources whose inputs have not changed All of these situations are confusing at the very least, and the first is problematic with respect to correctness. Furthermore, the display code only renders diffs it observes rather than rendering the diffs observed by the provider, which can obscure the actual changes detected at runtime. These changes address both of these issues: - Rather than comparing the current inputs against the last inputs before calling a resource provider's Diff function, the engine calls the Diff function in all cases. - Providers may now return a list of properties that differ between the requested and actual state and the way in which they differ. This information will then be used by the CLI to render the diff appropriately. A provider may also indicate that a particular diff is between old and new inputs rather than old state and new inputs. Fixes #2453.
2019-07-01 19:34:19 +00:00
DetailedDiff: c.detailedDiff,
Change `pulumi refresh` to report diff relative to desired state instead of relative to only output changes (#16146) Presently, the behaviour of diffing during refresh steps is incomplete, returning only an "output diff" that presents the changes in outputs. This commit changes refresh steps so that: * they compute a diff similar to the one that would be computed if a `preview` were run immediately after the refresh, which is more typically what users expect and want; and * `IgnoreChanges` resource options are respected when performing the new desired-state diffs, so that property additions or changes reported by a refresh can be ignored. In particular, `IgnoreChanges` can now be used to acknowledge that part or all of a resource may change in the provider, but the user is OK with this and doesn't want to be notified about it during a refresh. Importantly, this means that the diff won't be reported, but also that the changes won't be applied to state. The implementation covers the following: * A diff is computed using the inputs from the program and then inverting the result, since in the case of a refresh the diff is being driven by the provider side and not the program. This doesn't change what is stored back into the state, but it does produce a diff that is more aligned with the "true changes to the desired state". * `IgnoreChanges` resource options are now stored in state, so that this information can be used in refresh operations that do not have access to/run the program. * In the context of a refresh operation, `IgnoreChanges` applies to *both* input and output properties. This differs from the behaviour of a normal update operation, where `IgnoreChanges` only considers input properties. * The special `"*"` value for `IgnoreChanges` can be used to ignore all properties. It _also_ ignores the case where the resource cannot be found in the provider, and instead keeps the resource intact in state with its existing input and output properties. Because the program is not run for refresh operations, `IgnoreChanges` options must be applied separately before a refresh takes place. This can be accomplished using e.g. a `pulumi up` that applies the options prior to a refresh. We should investigate perhaps providing a `pulumi state set ...`-like CLI to make these sorts of changes directly to a state. For use cases relying on the legacy refresh diff provider, the `PULUMI_USE_LEGACY_REFRESH_DIFF` environment variable can be set, which will disable desired-state diff computation. We only need to perform checks in `RefreshStep.{ResultOp,Apply}`, since downstream code will work correctly based on the presence or absence of a `DetailedDiff` in the step. ### Notes - https://github.com/pulumi/pulumi/issues/16144 affects some of these cases - though its technically orthogonal - https://github.com/pulumi/pulumi/issues/11279 is another technically orthogonal issue that many providers (at least TFBridge ones) - do not report back changes to input properties on Read when the input property (or property path) was missing on the inputs. This is again technically orthogonal - but leads to cases that appear "wrong" in terms of what is stored back into the state still - though the same as before this change. - Azure Native doesn't seem to handle `ignoreChanges` passed to Diff, so the ability to ignore changes on refresh doesn't currently work for Azure Native. ### Fixes * Fixes #16072 * Fixes #16278 * Fixes #16334 * Not quite #12346, but likely replaces the need for that Co-authored-by: Will Jones <will@sacharissa.co.uk>
2024-06-12 16:17:05 +00:00
}, false)
Defer all diffs to resource providers. (#2849) Thse changes make a subtle but critical adjustment to the process the Pulumi engine uses to determine whether or not a difference exists between a resource's actual and desired states, and adjusts the way this difference is calculated and displayed accordingly. Today, the Pulumi engine get the first chance to decide whether or not there is a difference between a resource's actual and desired states. It does this by comparing the current set of inputs for a resource (i.e. the inputs from the running Pulumi program) with the last set of inputs used to update the resource. If there is no difference between the old and new inputs, the engine decides that no change is necessary without consulting the resource's provider. Only if there are changes does the engine consult the resource's provider for more information about the difference. This can be problematic for a number of reasons: - Not all providers do input-input comparison; some do input-state comparison - Not all providers are able to update the last deployed set of inputs when performing a refresh - Some providers--either intentionally or due to bugs--may see changes in resources whose inputs have not changed All of these situations are confusing at the very least, and the first is problematic with respect to correctness. Furthermore, the display code only renders diffs it observes rather than rendering the diffs observed by the provider, which can obscure the actual changes detected at runtime. These changes address both of these issues: - Rather than comparing the current inputs against the last inputs before calling a resource provider's Diff function, the engine calls the Diff function in all cases. - Providers may now return a list of properties that differ between the requested and actual state and the way in which they differ. This information will then be used by the CLI to render the diff appropriately. A provider may also indicate that a particular diff is between old and new inputs rather than old state and new inputs. Fixes #2453.
2019-07-01 19:34:19 +00:00
assert.Equal(t, c.expected, diff)
}
}