pulumi / pulumi-yaml

YAML language provider for Pulumi
Apache License 2.0
39 stars 12 forks source link

`pulumi up` with invalid resource options panics #465

Closed iwahbe closed 1 year ago

iwahbe commented 1 year ago

What happened?

I ran pulumi up on the following program:

name: test2
runtime: yaml
description: A minimal AWS Pulumi YAML program
outputs:
  # Export the name of the bucket
  bucketName: ${my-bucket.id}
resources:
  # Create an AWS resource (S3 Bucket)
  my-bucket:
    type: aws:s3:Bucket
  options:
    version: v6.0.0-alpha.5
config:
  aws:region: us-east-1

I got:

𝛌 pulumi up
Previewing update (dev)

View in Browser (Ctrl+O): https://app.pulumi.com/pulumi/test2/dev/previews/010d5cff-e82a-473b-8e90-0fbbb33dc766

     Type                 Name       Plan       Info
 +   pulumi:pulumi:Stack  test2-dev  create     1 error; 33 messages

Diagnostics:
  pulumi:pulumi:Stack (test2-dev):
    Warning: Field 'version' does not exist on Object 'resources.options'
      on Pulumi.yaml line 12:
      12:     version: v6.0.0-alpha.5
    Existing fields are: 'options', 'get', 'type', 'properties', 'defaultProvider'
    panic: runtime error: invalid memory address or nil pointer dereference
    [signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0x1a29126]
    goroutine 55 [running]:
    github.com/pulumi/pulumi-yaml/pkg/pulumiyaml.(*Runner).setDefaultProviders(0xc0005a8400)
        /Users/ianwahbe/go/src/github.com/pulumi/pulumi-yaml/pkg/pulumiyaml/run.go:192 +0x1c6
    github.com/pulumi/pulumi-yaml/pkg/pulumiyaml.PrepareTemplate(0xc0005a8400?, 0x20?, {0x1e81390?, 0xc00043c480?})
        /Users/ianwahbe/go/src/github.com/pulumi/pulumi-yaml/pkg/pulumiyaml/run.go:316 +0x146
    github.com/pulumi/pulumi-yaml/pkg/pulumiyaml.RunTemplate(0xc00071d1b0?, 0xc0000bc800, 0xc00058cf30?, {0x1e81390?, 0xc00043c480})
        /Users/ianwahbe/go/src/github.com/pulumi/pulumi-yaml/pkg/pulumiyaml/run.go:331 +0x1ab
    github.com/pulumi/pulumi-yaml/pkg/server.(*yamlLanguageHost).Run.func1(0x1c8ff00?)
        /Users/ianwahbe/go/src/github.com/pulumi/pulumi-yaml/pkg/server/server.go:171 +0x355
    github.com/pulumi/pulumi/sdk/v3/go/pulumi.RunWithContext(0xc000614160, 0xc00053f698)
        /Users/ianwahbe/go/pkg/mod/github.com/pulumi/pulumi/sdk/v3@v3.53.1/go/pulumi/run.go:121 +0x1aa
    github.com/pulumi/pulumi-yaml/pkg/server.(*yamlLanguageHost).Run(0xc000193e00, {0x1e845a8, 0xc0002fd380}, 0xc0000344e0)
        /Users/ianwahbe/go/src/github.com/pulumi/pulumi-yaml/pkg/server/server.go:157 +0x726
    github.com/pulumi/pulumi/sdk/v3/proto/go._LanguageRuntime_Run_Handler.func1({0x1e845a8, 0xc0002fd380}, {0x1c43c80?, 0xc0000344e0})
        /Users/ianwahbe/go/pkg/mod/github.com/pulumi/pulumi/sdk/v3@v3.53.1/proto/go/language_grpc.pb.go:249 +0x78
    github.com/grpc-ecosystem/grpc-opentracing/go/otgrpc.OpenTracingServerInterceptor.func1({0x1e845a8, 0xc0002fcd80}, {0x1c43c80, 0xc0000344e0}, 0xc000458f60, 0xc0004e0b58)
        /Users/ianwahbe/go/pkg/mod/github.com/grpc-ecosystem/grpc-opentracing@v0.0.0-20180507213350-8e809c8a8645/go/otgrpc/server.go:57 +0x3f9
    github.com/pulumi/pulumi/sdk/v3/proto/go._LanguageRuntime_Run_Handler({0x1c06d80?, 0xc000193e00}, {0x1e845a8, 0xc0002fcd80}, 0xc000342d20, 0xc000582060)
        /Users/ianwahbe/go/pkg/mod/github.com/pulumi/pulumi/sdk/v3@v3.53.1/proto/go/language_grpc.pb.go:251 +0x138
    google.golang.org/grpc.(*Server).processUnaryRPC(0xc0006fa000, {0x1e8ab20, 0xc0001831e0}, 0xc000570480, 0xc0006cd4d0, 0x258f6d8, 0x0)
        /Users/ianwahbe/go/pkg/mod/google.golang.org/grpc@v1.51.0/server.go:1340 +0xd23
    google.golang.org/grpc.(*Server).handleStream(0xc0006fa000, {0x1e8ab20, 0xc0001831e0}, 0xc000570480, 0x0)
        /Users/ianwahbe/go/pkg/mod/google.golang.org/grpc@v1.51.0/server.go:1713 +0xa2f
    google.golang.org/grpc.(*Server).serveStreams.func1.2()
        /Users/ianwahbe/go/pkg/mod/google.golang.org/grpc@v1.51.0/server.go:965 +0x98
    created by google.golang.org/grpc.(*Server).serveStreams.func1
        /Users/ianwahbe/go/pkg/mod/google.golang.org/grpc@v1.51.0/server.go:963 +0x28a

    error: error reading from server: EOF

Policy Packs run:
    Name                      Version
    pulumi-internal-policies  6

Expected Behavior

I expect that invalid input will lead to a useful error.

Steps to reproduce

Run pulumi up on the provided program.

Output of pulumi about

CLI          
Version      3.76.0-dev.0
Go Version   go1.20.6
Go Compiler  gc

Plugins
NAME  VERSION
yaml  unknown

Host     
OS       darwin
Version  13.4
Arch     arm64

This project is written in yaml

Current Stack: pulumi/test2/dev

Found no resources associated with dev

Found no pending operations associated with dev

Backend        
Name           pulumi.com
URL            https://app.pulumi.com/ian-pulumi-corp
User           ian-pulumi-corp
Organizations  ian-pulumi-corp, pulumi

No dependencies found

Pulumi locates its logs in /var/folders/fg/_1q36r4j6yx0rwz2fbhjd5y40000gn/T/ 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).

justinvp commented 1 year ago

The main problem with the following is that options needs to be indented to be under my-bucket:

name: test2
runtime: yaml
description: A minimal AWS Pulumi YAML program
outputs:
  bucketName: ${my-bucket.id}
resources:
  my-bucket:
    type: aws:s3:Bucket
  options:                        <-- should be indented one more level to be under `my-bucket`
    version: v6.0.0-alpha.5

If left this way, the program is specifying two resources:

  1. my-bucket
  2. options

but options does not have a type specified, which leads to a panic

https://github.com/pulumi/pulumi-yaml/pull/468 fixes this not to panic, and provides a more useful error message when a resource is missing a type field:

Error: Required field 'type' is missing on resource "options"
      on Pulumi.yaml line 10:
      10:     version: v6.0.0-alpha.5