Skip to content

Adding a ForceNew field with a default becomes a breaking change in Pulumi #2915

@t0yv0

Description

@t0yv0

What happened?

Adding a ForceNew field with a default becomes a breaking change in Pulumi where it is a no-op in Terraform. What is more confusing to reproduce the issue some other field needs to be changing simultaneously.

That is we have a bug with replacement plan attribution.

Example

// Test that adding a ForceNew field with a default is not a breaking change.
func TestAddForceNewField(t *testing.T) {
	t.Parallel()

	bridgedProvider0 := pulcheck.BridgedProvider(t, "prov", &schema.Provider{
		ResourcesMap: map[string]*schema.Resource{
			"prov_test": {
				Schema: map[string]*schema.Schema{
					"x": {
						Type:     schema.TypeString,
						Optional: true,
					},
				},
			},
		},
	})

	bridgedProvider1 := pulcheck.BridgedProvider(t, "prov", &schema.Provider{
		ResourcesMap: map[string]*schema.Resource{
			"prov_test": {
				Schema: map[string]*schema.Schema{
					"x": {
						Type:     schema.TypeString,
						Optional: true,
					},
					"test": {
						Type:     schema.TypeBool,
						Optional: true,
						Default:  false,
						ForceNew: true,
					},
				},
			},
		},
	})

	program0 := `
name: test
runtime: yaml
resources:
  mainRes:
    type: prov:index:Test
    properties:
     x: "v1"
`
	program1 := `
name: test
runtime: yaml
resources:
  mainRes:
    type: prov:index:Test
    properties:
     x: "v2"
`

	pt0 := pulcheck.PulCheck(t, bridgedProvider0, program0)
	pt0.Up(t)
	state := pt0.ExportStack(t)

	pt1 := pulcheck.PulCheck(t, bridgedProvider1, program1)
	pt1.ImportStack(t, state)
	preview := pt1.Preview(t, optpreview.Diff())
	t.Logf("%s", preview.StdOut)
	t.Logf("%v", preview.ChangeSummary)

	require.Equal(t, 0, preview.ChangeSummary["replace"])
}

Output of pulumi about

N/A

Additional context

The original context for this is in pulumi/pulumi-aws#5229

Contributing

Vote on this issue by adding a 👍 reaction.
To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugSome behavior is incorrect or out of spec

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions