pulumi / pulumi-command

Apache License 2.0
65 stars 26 forks source link

`refresh` breaks `Command.assets` #537

Open RafalSumislawski opened 2 months ago

RafalSumislawski commented 2 months ago

What happened?

Give a code that attempts to use the assets output of a Command resource:

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

new command.local.Command(`test-file`, {
    create: "touch test.txt",
    assetPaths: ["test.txt"],
}).assets.apply(assets => {
    assets
});

running a sequence of

pulumi up
pulumi refresh
pulumi up

Leads to a Invalid asset encountered when unmarshaling resource property error.

This is most likely related to the fact that running a refresh removes the path property of the asset

Before:

                        "assets": {
                            "test.txt": {
                                "4dabf18193072939515e22adb298388d": "c44067f5952c0a294b673a41bacd8c17",
                                "hash": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
                                "path": "/Users/rsum/pulumi/main/test.txt"
                            }
                        },

After:

                        "assets": {
                            "test.txt": {
                                "4dabf18193072939515e22adb298388d": "c44067f5952c0a294b673a41bacd8c17",
                                "hash": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
                            }
                        },

Example


% pulumi up                         
Previewing update (rafal):
     Type                      Name            Plan       
 +   pulumi:pulumi:Stack       command-test-rafal  create     
 +   └─ command:local:Command  test-file       create     

Resources:
    + 2 to create

Do you want to perform this update? yes
Updating (rafal):
     Type                      Name            Status              
 +   pulumi:pulumi:Stack       command-test-rafal  created (1s)        
 +   └─ command:local:Command  test-file       created (0.09s)     

Resources:
    + 2 created

Duration: 2s

% pulumi refresh
Previewing refresh (rafal):
     Type                      Name            Plan     
     pulumi:pulumi:Stack       command-test-rafal           
     └─ command:local:Command  test-file                

Resources:
    2 unchanged

Do you want to perform this refresh?
No resources will be modified as part of this refresh; just your stack's state will be.
 yes
Refreshing (rafal):
     Type                      Name            Status     
     pulumi:pulumi:Stack       command-test-rafal             
     └─ command:local:Command  test-file                  

Resources:
    2 unchanged

Duration: 1s

% pulumi up     
Previewing update (rafal):
     Type                 Name            Plan     Info
     pulumi:pulumi:Stack  command-test-rafal           1 error

Diagnostics:
  pulumi:pulumi:Stack (command-test-rafal):
    error: Running program '/Users/rsum/pulumi/main/index.ts' failed with an unhandled exception:
    <ref *1> Error: Invalid asset encountered when unmarshaling resource property
        at deserializeProperty (/Users/rsum/pulumi/main/node_modules/.pnpm/@pulumi+pulumi@3.131.0_typescript@5.5.4/node_modules/@pulumi/runtime/rpc.ts:636:31)
        at deserializeProperty (/Users/rsum/pulumi/main/node_modules/.pnpm/@pulumi+pulumi@3.131.0_typescript@5.5.4/node_modules/@pulumi/runtime/rpc.ts:732:23)
        at Object.deserializeProperties (/Users/rsum/pulumi/main/node_modules/.pnpm/@pulumi+pulumi@3.131.0_typescript@5.5.4/node_modules/@pulumi/runtime/rpc.ts:200:24)
        at /Users/rsum/pulumi/main/node_modules/.pnpm/@pulumi+pulumi@3.131.0_typescript@5.5.4/node_modules/@pulumi/runtime/resource.ts:1104:33
        at Generator.next (<anonymous>)
        at /Users/rsum/pulumi/main/node_modules/.pnpm/@pulumi+pulumi@3.131.0_typescript@5.5.4/node_modules/@pulumi/pulumi/runtime/resource.js:21:71
        at new Promise (<anonymous>)
        at __awaiter (/Users/rsum/pulumi/main/node_modules/.pnpm/@pulumi+pulumi@3.131.0_typescript@5.5.4/node_modules/@pulumi/pulumi/runtime/resource.js:17:12)
        at resolveOutputs (/Users/rsum/pulumi/main/node_modules/.pnpm/@pulumi+pulumi@3.131.0_typescript@5.5.4/node_modules/@pulumi/pulumi/runtime/resource.js:797:12)
        at Object.<anonymous> (/Users/rsum/pulumi/main/node_modules/.pnpm/@pulumi+pulumi@3.131.0_typescript@5.5.4/node_modules/@pulumi/runtime/resource.ts:701:23)
        at Generator.next (<anonymous>)
        at fulfilled (/Users/rsum/pulumi/main/node_modules/.pnpm/@pulumi+pulumi@3.131.0_typescript@5.5.4/node_modules/@pulumi/pulumi/runtime/resource.js:18:58)
        at processTicksAndRejections (node:internal/process/task_queues:95:5) {
      promise: Promise { <rejected> [Circular *1] }
    }

### Output of `pulumi about`

pulumi about
CLI          
Version      3.132.0
Go Version   go1.23.1
Go Compiler  gc

Plugins
KIND      NAME     VERSION
resource  command  1.0.1
resource  gcp      7.38.0
language  nodejs   unknown

Host     
OS       darwin
Version  14.6.1
Arch     arm64

This project is written in nodejs: executable='/Users/rsum/.nvm/versions/node/v18.13.0/bin/node' version='v18.13.0'

Current Stack: organization/command-test/rafal

TYPE                      URN
pulumi:pulumi:Stack       urn:pulumi:rafal::command-test::pulumi:pulumi:Stack::command-test-rafal
pulumi:providers:command  urn:pulumi:rafal::command-test::pulumi:providers:command::default_1_0_1
command:local:Command     urn:pulumi:rafal::command-test::command:local:Command::test-file

Found no pending operations associated with rafal

Backend        
Name           Rafas-MacBook-Pro.local
URL            file://~
User           rsum
Organizations  
Token type     personal

Pulumi locates its logs in /var/folders/bk/z20y93815gnglbl_xdtjwjjh0000gn/T/ by default
warning: Failed to get information about the Pulumi program's dependencies: could not find either /Users/rsum/pulumi/main/yarn.lock or /Users/rsum/pulumi/main/package-lock.json

### 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). 
mjeffryes commented 2 months ago

Thanks for the bug report @RafalSumislawski. I think the root cause here is https://github.com/pulumi/pulumi/issues/17131 I'll keep this open as a pointer for other users, but I suggest, upvoting and adding any additional context on that ticket.