Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The --expect-no-changes flag checks for output diffs #15903

Merged
merged 3 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
changes:
- type: fix
scope: cli/engine
description: "Make --expect-no-changes fail even if the only changes are output changes"
4 changes: 4 additions & 0 deletions pkg/backend/display/progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -1137,6 +1137,8 @@ func (display *ProgressDisplay) getStepDoneDescription(step engine.StepEventMeta
opText = "discarding failed"
case deploy.OpImport, deploy.OpImportReplacement:
opText = "importing failed"
case deploy.OpOutputChange:
opText = "changing output failed"
default:
contract.Failf("Unrecognized resource step op: %v", op)
return ""
Expand Down Expand Up @@ -1171,6 +1173,8 @@ func (display *ProgressDisplay) getStepDoneDescription(step engine.StepEventMeta
opText = "imported"
case deploy.OpImportReplacement:
opText = "imported replacement"
case deploy.OpOutputChange:
opText = "output changed"
default:
contract.Failf("Unrecognized resource step op: %v", op)
return ""
Expand Down
2 changes: 2 additions & 0 deletions pkg/backend/httpstate/snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/pulumi/pulumi/pkg/v3/backend/httpstate/client"
"github.com/pulumi/pulumi/pkg/v3/display"
"github.com/pulumi/pulumi/pkg/v3/engine"
"github.com/pulumi/pulumi/pkg/v3/engine/lifecycletest"
"github.com/pulumi/pulumi/pkg/v3/resource/deploy"
Expand Down Expand Up @@ -316,6 +317,7 @@ func generateSnapshots(t testing.TB, r *rand.Rand, resourceCount, resourcePayloa
_ deploy.Target,
entries engine.JournalEntries,
_ []engine.Event,
_ display.ResourceChanges,
_ error,
) error {
journalEntries = entries
Expand Down
7 changes: 6 additions & 1 deletion pkg/cmd/pulumi/stack_history.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/pulumi/pulumi/pkg/v3/backend"
"github.com/pulumi/pulumi/pkg/v3/backend/display"
"github.com/pulumi/pulumi/pkg/v3/resource/deploy"
"github.com/pulumi/pulumi/sdk/v3/go/common/diag/colors"
"github.com/pulumi/pulumi/sdk/v3/go/common/resource/config"
"github.com/pulumi/pulumi/sdk/v3/go/common/util/cmdutil"
Expand Down Expand Up @@ -162,7 +163,11 @@ func displayUpdatesJSON(updates []backend.UpdateInfo, decrypter config.Decrypter
info.EndTime = makeStringRef(time.Unix(update.EndTime, 0).UTC().Format(timeFormat))
resourceChanges := make(map[string]int)
for k, v := range update.ResourceChanges {
resourceChanges[string(k)] = v
// Filter out the the OpOutputChange events because they are pseudo
// events that shouldn't be included in the stack history
if k != deploy.OpOutputChange {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we filter out OpOutputChange here? That's not obvious from context, deserves an explanation comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment

resourceChanges[string(k)] = v
}
}
info.ResourceChanges = &resourceChanges
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/engine/lifecycletest/alias_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func createUpdateProgramWithResourceFuncForAliasTests(
Op: Update,
ExpectFailure: expectFailure,
Validate: func(project workspace.Project, target deploy.Target, entries JournalEntries,
events []Event, err error,
events []Event, changes display.ResourceChanges, err error,
) error {
for _, event := range events {
if event.Type == ResourcePreEvent {
Expand Down Expand Up @@ -1595,7 +1595,7 @@ func TestParentAlias(t *testing.T) {
firstRun = false
snap, err = TestOp(Update).Run(project, p.GetTarget(t, snap), p.Options, false, p.BackendClient,
func(project workspace.Project, target deploy.Target,
entries JournalEntries, events []Event, err error,
entries JournalEntries, events []Event, changes display.ResourceChanges, err error,
) error {
for _, entry := range entries {
assert.Equal(t, deploy.OpSame, entry.Step.Op())
Expand Down Expand Up @@ -1669,7 +1669,7 @@ func TestEmptyParentAlias(t *testing.T) {
firstRun = false
snap, err = TestOp(Update).Run(project, p.GetTarget(t, snap), p.Options, false, p.BackendClient,
func(project workspace.Project, target deploy.Target,
entries JournalEntries, events []Event, err error,
entries JournalEntries, events []Event, changes display.ResourceChanges, err error,
) error {
for _, entry := range entries {
assert.Equal(t, deploy.OpSame, entry.Step.Op())
Expand Down
5 changes: 3 additions & 2 deletions pkg/engine/lifecycletest/analyzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"testing"

"github.com/blang/semver"
"github.com/pulumi/pulumi/pkg/v3/display"
. "github.com/pulumi/pulumi/pkg/v3/engine" //nolint:revive
"github.com/pulumi/pulumi/pkg/v3/resource/deploy"
"github.com/pulumi/pulumi/pkg/v3/resource/deploy/deploytest"
Expand Down Expand Up @@ -375,7 +376,7 @@ func TestSimpleAnalyzeResourceFailureRemediateDowngradedToMandatory(t *testing.T
SkipPreview: true,
ExpectFailure: true,
Validate: func(project workspace.Project, target deploy.Target, entries JournalEntries,
events []Event, err error,
events []Event, changes display.ResourceChanges, err error,
) error {
violationEvents := []Event{}
for _, e := range events {
Expand Down Expand Up @@ -439,7 +440,7 @@ func TestSimpleAnalyzeStackFailureRemediateDowngradedToMandatory(t *testing.T) {
SkipPreview: true,
ExpectFailure: true,
Validate: func(project workspace.Project, target deploy.Target, entries JournalEntries,
events []Event, err error,
events []Event, changes display.ResourceChanges, err error,
) error {
violationEvents := []Event{}
for _, e := range events {
Expand Down
17 changes: 9 additions & 8 deletions pkg/engine/lifecycletest/delete_before_replace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/stretchr/testify/require"
"golang.org/x/exp/maps"

"github.com/pulumi/pulumi/pkg/v3/display"
. "github.com/pulumi/pulumi/pkg/v3/engine" //nolint:revive
"github.com/pulumi/pulumi/pkg/v3/resource/deploy"
"github.com/pulumi/pulumi/pkg/v3/resource/deploy/deploytest"
Expand Down Expand Up @@ -176,7 +177,7 @@ func TestDeleteBeforeReplace(t *testing.T) {
ExpectFailure: false,
SkipPreview: true,
Validate: func(project workspace.Project, target deploy.Target, entries JournalEntries,
evts []Event, err error,
evts []Event, changes display.ResourceChanges, err error,
) error {
assert.NoError(t, err)

Expand Down Expand Up @@ -350,7 +351,7 @@ func TestExplicitDeleteBeforeReplace(t *testing.T) {
Op: Update,

Validate: func(project workspace.Project, target deploy.Target, entries JournalEntries,
evts []Event, err error,
evts []Event, changes display.ResourceChanges, err error,
) error {
assert.NoError(t, err)

Expand All @@ -374,7 +375,7 @@ func TestExplicitDeleteBeforeReplace(t *testing.T) {
Op: Update,

Validate: func(project workspace.Project, target deploy.Target, entries JournalEntries,
evts []Event, err error,
evts []Event, changes display.ResourceChanges, err error,
) error {
assert.NoError(t, err)

Expand All @@ -399,7 +400,7 @@ func TestExplicitDeleteBeforeReplace(t *testing.T) {
Op: Update,

Validate: func(project workspace.Project, target deploy.Target, entries JournalEntries,
evts []Event, err error,
evts []Event, changes display.ResourceChanges, err error,
) error {
assert.NoError(t, err)

Expand All @@ -423,7 +424,7 @@ func TestExplicitDeleteBeforeReplace(t *testing.T) {
Op: Update,

Validate: func(project workspace.Project, target deploy.Target, entries JournalEntries,
evts []Event, err error,
evts []Event, changes display.ResourceChanges, err error,
) error {
assert.NoError(t, err)

Expand All @@ -447,7 +448,7 @@ func TestExplicitDeleteBeforeReplace(t *testing.T) {
Op: Update,

Validate: func(project workspace.Project, target deploy.Target, entries JournalEntries,
evts []Event, err error,
evts []Event, changes display.ResourceChanges, err error,
) error {
assert.NoError(t, err)

Expand All @@ -473,7 +474,7 @@ func TestExplicitDeleteBeforeReplace(t *testing.T) {
Op: Update,

Validate: func(project workspace.Project, target deploy.Target, entries JournalEntries,
evts []Event, err error,
evts []Event, changes display.ResourceChanges, err error,
) error {
assert.NoError(t, err)

Expand Down Expand Up @@ -575,7 +576,7 @@ func TestDependencyChangeDBR(t *testing.T) {
{
Op: Update,
Validate: func(project workspace.Project, target deploy.Target, entries JournalEntries,
evts []Event, err error,
evts []Event, changes display.ResourceChanges, err error,
) error {
assert.NoError(t, err)
assert.True(t, len(entries) > 0)
Expand Down
10 changes: 5 additions & 5 deletions pkg/engine/lifecycletest/golang_sdk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func TestIgnoreChangesGolangLifecycle(t *testing.T) {
{
Op: Update,
Validate: func(project workspace.Project, target deploy.Target, entries JournalEntries,
events []Event, err error,
events []Event, changes display.ResourceChanges, err error,
) error {
for _, event := range events {
if event.Type == ResourcePreEvent {
Expand Down Expand Up @@ -262,7 +262,7 @@ func TestExplicitDeleteBeforeReplaceGoSDK(t *testing.T) {
Op: Update,

Validate: func(project workspace.Project, target deploy.Target, entries JournalEntries,
evts []Event, err error,
evts []Event, changes display.ResourceChanges, err error,
) error {
assert.NoError(t, err)

Expand All @@ -286,7 +286,7 @@ func TestExplicitDeleteBeforeReplaceGoSDK(t *testing.T) {
Op: Update,

Validate: func(project workspace.Project, target deploy.Target, entries JournalEntries,
evts []Event, err error,
evts []Event, changes display.ResourceChanges, err error,
) error {
assert.NoError(t, err)
AssertSameSteps(t, []StepSummary{
Expand Down Expand Up @@ -349,7 +349,7 @@ func TestReadResourceGolangLifecycle(t *testing.T) {
{
Op: Update,
Validate: func(project workspace.Project, target deploy.Target, entries JournalEntries,
evts []Event, err error,
evts []Event, changes display.ResourceChanges, err error,
) error {
assert.NoError(t, err)

Expand Down Expand Up @@ -598,7 +598,7 @@ func TestReplaceOnChangesGolangLifecycle(t *testing.T) {
{
Op: Update,
Validate: func(project workspace.Project, target deploy.Target, entries JournalEntries,
events []Event, err error,
events []Event, changes display.ResourceChanges, err error,
) error {
collectedOps := make([]display.StepOp, 0)
for _, event := range events {
Expand Down
49 changes: 37 additions & 12 deletions pkg/engine/lifecycletest/import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/pulumi/pulumi/pkg/v3/display"
. "github.com/pulumi/pulumi/pkg/v3/engine" //nolint:revive
"github.com/pulumi/pulumi/pkg/v3/resource/deploy"
"github.com/pulumi/pulumi/pkg/v3/resource/deploy/deploytest"
Expand Down Expand Up @@ -103,7 +104,9 @@ func TestImportOption(t *testing.T) {
// Run a second update after fixing the inputs. The import should succeed.
inputs["foo"] = resource.NewStringProperty("bar")
snap, err := TestOp(Update).Run(project, p.GetTarget(t, nil), p.Options, false, p.BackendClient,
func(_ workspace.Project, _ deploy.Target, entries JournalEntries, _ []Event, err error) error {
func(_ workspace.Project, _ deploy.Target, entries JournalEntries, _ []Event,
_ display.ResourceChanges, err error,
) error {
for _, entry := range entries {
switch urn := entry.Step.URN(); urn {
case provURN:
Expand All @@ -123,7 +126,9 @@ func TestImportOption(t *testing.T) {

// Now, run another update. The update should succeed and there should be no diffs.
snap, err = TestOp(Update).Run(project, p.GetTarget(t, snap), p.Options, false, p.BackendClient,
func(_ workspace.Project, _ deploy.Target, entries JournalEntries, _ []Event, err error) error {
func(_ workspace.Project, _ deploy.Target, entries JournalEntries, _ []Event,
_ display.ResourceChanges, err error,
) error {
for _, entry := range entries {
switch urn := entry.Step.URN(); urn {
case provURN, resURN:
Expand All @@ -141,7 +146,9 @@ func TestImportOption(t *testing.T) {
// Change a property value and run a third update. The update should succeed.
inputs["foo"] = resource.NewStringProperty("rab")
snap, err = TestOp(Update).Run(project, p.GetTarget(t, snap), p.Options, false, p.BackendClient,
func(_ workspace.Project, _ deploy.Target, entries JournalEntries, _ []Event, err error) error {
func(_ workspace.Project, _ deploy.Target, entries JournalEntries, _ []Event,
_ display.ResourceChanges, err error,
) error {
for _, entry := range entries {
switch urn := entry.Step.URN(); urn {
case provURN:
Expand All @@ -166,7 +173,9 @@ func TestImportOption(t *testing.T) {

// Finally, destroy the stack. The `Delete` function should be called.
_, err = TestOp(Destroy).Run(project, p.GetTarget(t, snap), p.Options, false, p.BackendClient,
func(_ workspace.Project, _ deploy.Target, entries JournalEntries, _ []Event, err error) error {
func(_ workspace.Project, _ deploy.Target, entries JournalEntries, _ []Event,
_ display.ResourceChanges, err error,
) error {
for _, entry := range entries {
switch urn := entry.Step.URN(); urn {
case provURN, resURN:
Expand All @@ -182,7 +191,9 @@ func TestImportOption(t *testing.T) {
// Now clear the ID to import and run an initial update to create a resource that we will import-replace.
importID, inputs["foo"] = "", resource.NewStringProperty("bar")
snap, err = TestOp(Update).Run(project, p.GetTarget(t, nil), p.Options, false, p.BackendClient,
func(_ workspace.Project, _ deploy.Target, entries JournalEntries, _ []Event, err error) error {
func(_ workspace.Project, _ deploy.Target, entries JournalEntries, _ []Event,
_ display.ResourceChanges, err error,
) error {
for _, entry := range entries {
switch urn := entry.Step.URN(); urn {
case provURN, resURN:
Expand All @@ -206,7 +217,9 @@ func TestImportOption(t *testing.T) {
}
}
snap, err = TestOp(Update).Run(project, p.GetTarget(t, snap), p.Options, false, p.BackendClient,
func(_ workspace.Project, _ deploy.Target, entries JournalEntries, _ []Event, err error) error {
func(_ workspace.Project, _ deploy.Target, entries JournalEntries, _ []Event,
_ display.ResourceChanges, err error,
) error {
for _, entry := range entries {
switch urn := entry.Step.URN(); urn {
case provURN, resURN:
Expand All @@ -226,7 +239,9 @@ func TestImportOption(t *testing.T) {
// a delete-replaced.
importID = "id"
snap, err = TestOp(Update).Run(project, p.GetTarget(t, snap), p.Options, false, p.BackendClient,
func(_ workspace.Project, _ deploy.Target, entries JournalEntries, _ []Event, err error) error {
func(_ workspace.Project, _ deploy.Target, entries JournalEntries, _ []Event,
_ display.ResourceChanges, err error,
) error {
for _, entry := range entries {
switch urn := entry.Step.URN(); urn {
case provURN:
Expand All @@ -252,7 +267,9 @@ func TestImportOption(t *testing.T) {
readID = "id"
expectedInputs, expectedState = inputs, inputs
snap, err = TestOp(Update).Run(project, p.GetTarget(t, nil), p.Options, false, p.BackendClient,
func(_ workspace.Project, _ deploy.Target, entries JournalEntries, _ []Event, err error) error {
func(_ workspace.Project, _ deploy.Target, entries JournalEntries, _ []Event,
_ display.ResourceChanges, err error,
) error {
for _, entry := range entries {
switch urn := entry.Step.URN(); urn {
case provURN:
Expand All @@ -274,7 +291,9 @@ func TestImportOption(t *testing.T) {
readID, importID = "", readID
expectedInputs, expectedState = nil, nil
_, err = TestOp(Update).Run(project, p.GetTarget(t, snap), p.Options, false, p.BackendClient,
func(_ workspace.Project, _ deploy.Target, entries JournalEntries, _ []Event, err error) error {
func(_ workspace.Project, _ deploy.Target, entries JournalEntries, _ []Event,
_ display.ResourceChanges, err error,
) error {
for _, entry := range entries {
switch urn := entry.Step.URN(); urn {
case provURN:
Expand Down Expand Up @@ -364,7 +383,9 @@ func TestImportWithDifferingImportIdentifierFormat(t *testing.T) {
// Run the initial update. The import should succeed.
project := p.GetProject()
snap, err := TestOp(Update).Run(project, p.GetTarget(t, nil), p.Options, false, p.BackendClient,
func(_ workspace.Project, _ deploy.Target, entries JournalEntries, _ []Event, err error) error {
func(_ workspace.Project, _ deploy.Target, entries JournalEntries, _ []Event,
_ display.ResourceChanges, err error,
) error {
for _, entry := range entries {
switch urn := entry.Step.URN(); urn {
case provURN:
Expand All @@ -382,7 +403,9 @@ func TestImportWithDifferingImportIdentifierFormat(t *testing.T) {

// Now, run another update. The update should succeed and there should be no diffs.
_, err = TestOp(Update).Run(project, p.GetTarget(t, snap), p.Options, false, p.BackendClient,
func(_ workspace.Project, _ deploy.Target, entries JournalEntries, _ []Event, err error) error {
func(_ workspace.Project, _ deploy.Target, entries JournalEntries, _ []Event,
_ display.ResourceChanges, err error,
) error {
for _, entry := range entries {
switch urn := entry.Step.URN(); urn {
case provURN, resURN:
Expand Down Expand Up @@ -717,7 +740,9 @@ func TestImportPlanExistingImport(t *testing.T) {
Name: "resA",
ID: "imported-id",
}}).Run(project, p.GetTarget(t, snap), p.Options, false, p.BackendClient,
func(_ workspace.Project, _ deploy.Target, entries JournalEntries, _ []Event, _ error) error {
func(_ workspace.Project, _ deploy.Target, entries JournalEntries, _ []Event,
_ display.ResourceChanges, _ error,
) error {
for _, e := range entries {
assert.Equal(t, deploy.OpSame, e.Step.Op())
}
Expand Down