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

Inserting an element in a list presents as multiple edits #2239

Open
t0yv0 opened this issue Jul 23, 2024 · 4 comments · Fixed by #2863
Open

Inserting an element in a list presents as multiple edits #2239

t0yv0 opened this issue Jul 23, 2024 · 4 comments · Fixed by #2863
Labels
kind/bug Some behavior is incorrect or out of spec

Comments

@t0yv0
Copy link
Member

t0yv0 commented Jul 23, 2024

What happened?

Consider this program that inserts a new element into a TypeList property. When planning the change from step=0 to step=1, the user would expect Pulumi to display the planned change as an insertion at index 1. However, Pulumi does not recognize the insertion and instead projects multiple edits.

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const config = new pulumi.Config();

const step = config.requireNumber("step");

const lt = new aws.ec2.LaunchTemplate("lt", {
    blockDeviceMappings: step === 0
    ? [
        {deviceName: "/dev/sda",
         ebs: {volumeSize: 20}},
        {deviceName: "/dev/sdf",
         ebs: {volumeSize: 30}},
    ] : [
        {deviceName: "/dev/sda",
         ebs: {volumeSize: 20}},
        {deviceName: "/dev/sdb",
         ebs: {volumeSize: 25}},
        {deviceName: "/dev/sdf",
         ebs: {volumeSize: 30}},
    ],
});

export const ltId = lt.id;

repro:

#!/usr/bin/env bash

set -euo pipefail

pulumi destroy --yes

pulumi config set step 0
pulumi up --skip-preview

pulumi config set step 1
pulumi preview --diff
pulumi up --skip-preview

The diff is displayed like this:

  pulumi:pulumi:Stack: (same)
    [urn=urn:pulumi:dev::pulumi-terraform-bridge-2234::pulumi:pulumi:Stack::pulumi-terraform-bridge-2234-dev]
    ~ aws:ec2/launchTemplate:LaunchTemplate: (update)
        [id=lt-030db90b79c0adb92]
        [urn=urn:pulumi:dev::pulumi-terraform-bridge-2234::aws:ec2/launchTemplate:LaunchTemplate::lt]
        [provider=urn:pulumi:dev::pulumi-terraform-bridge-2234::pulumi:providers:aws::default_6_45_0::e2444379-04b7-4ae1-8801-cf60ad99fc48]
      ~ blockDeviceMappings: [
          ~ [0]: {
                  + __defaults : []
                    deviceName : "/dev/sda"
                  ~ ebs        : {
                      + __defaults         : []
                      - deleteOnTermination: ""
                      - encrypted          : ""
                      - iops               : 0
                      - kmsKeyId           : ""
                      - snapshotId         : ""
                      - throughput         : 0
                        volumeSize         : 20
                      - volumeType         : ""
                    }
                  - noDevice   : ""
                  - virtualName: ""
                }
          ~ [1]: {
                  + __defaults : []
                  ~ deviceName : "/dev/sdf" => "/dev/sdb"
                  ~ ebs        : {
                      + __defaults         : []
                      - deleteOnTermination: ""
                      - encrypted          : ""
                      - iops               : 0
                      - kmsKeyId           : ""
                      - snapshotId         : ""
                      - throughput         : 0
                      ~ volumeSize         : 30 => 25
                      - volumeType         : ""
                    }
                  - noDevice   : ""
                  - virtualName: ""
                }
          + [2]: {
                  + deviceName: "/dev/sdf"
                  + ebs       : {
                      + volumeSize: 30
                    }
                }
        ]
Resources:              
    ~ 1 to update
    1 unchanged
Updating (dev)

Disregarding the empty/missing diff entries that are confusing, the diff still thinks that elements at index 1,2 were edited, instead of thinking of this change as a plain insertion/addition at index 1. This can be confusing especially for large collections.

Example

See above.

Output of pulumi about

CLI          
Version      3.124.0
Go Version   go1.22.5
Go Compiler  gc

Plugins
KIND      NAME    VERSION
resource  aws     6.45.0
resource  awsx    2.13.0
resource  docker  4.5.4
resource  docker  3.6.1
language  nodejs  unknown

Host     
OS       darwin
Version  14.5
Arch     arm64

This project is written in nodejs: executable='/Users/anton/bin/node' version='v18.18.2'

Current Stack: anton-pulumi-corp/pulumi-terraform-bridge-2234/dev

TYPE                                   URN
pulumi:pulumi:Stack                    urn:pulumi:dev::pulumi-terraform-bridge-2234::pulumi:pulumi:Stack::pulumi-terraform-bridge-2234-dev
pulumi:providers:aws                   urn:pulumi:dev::pulumi-terraform-bridge-2234::pulumi:providers:aws::default_6_45_0
aws:ec2/launchTemplate:LaunchTemplate  urn:pulumi:dev::pulumi-terraform-bridge-2234::aws:ec2/launchTemplate:LaunchTemplate::lt


Found no pending operations associated with dev

Backend        
Name           pulumi.com
URL            https://app.pulumi.com/anton-pulumi-corp
User           anton-pulumi-corp
Organizations  anton-pulumi-corp, moolumi, demo, pulumi
Token type     personal

Dependencies:
NAME            VERSION
typescript      5.5.4
@pulumi/aws     6.45.0
@pulumi/awsx    2.13.0
@pulumi/pulumi  3.126.0
@types/node     18.19.41

Pulumi locates its logs in /var/folders/gd/3ncjb1lj5ljgk8xl5ssn_gvc0000gn/T/com.apple.shortcuts.mac-helper// by default

Additional context

No response

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).

@t0yv0 t0yv0 added kind/bug Some behavior is incorrect or out of spec needs-triage Needs attention from the triage team labels Jul 23, 2024
@t0yv0
Copy link
Member Author

t0yv0 commented Jul 23, 2024

CC @VenelinMartinov another example of collection insertion diffs. To resolve we might need something like minimal edit distance detection https://github.com/t0yv0/godifft

@t0yv0
Copy link
Member Author

t0yv0 commented Jan 28, 2025

This is not fixed because if I understand the fix correctly it is scoped down to lists of primitive types such as "string" on account of TF doing this and additional implementation difficulty presented by attributing "replace" to a particular sub-property causing replacements? Is this right? In fact the LaunchTemplate example wouldn't be fixed as yet?

@VenelinMartinov
Copy link
Contributor

Yup, that's correct.

@VenelinMartinov VenelinMartinov removed their assignment Jan 28, 2025
@VenelinMartinov VenelinMartinov removed the resolution/fixed This issue was fixed label Jan 28, 2025
@pulumi-bot
Copy link
Contributor

This issue has been addressed in PR #2863 and shipped in release v3.103.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Some behavior is incorrect or out of spec
Projects
None yet
4 participants