pulumi / pulumi

Pulumi - Infrastructure as Code in any programming language 🚀
https://www.pulumi.com
Apache License 2.0
20.81k stars 1.08k forks source link

[sdk/go] RegisterResourceOutputs does not result in any outputs #11749

Open daenney opened 1 year ago

daenney commented 1 year ago

What happened?

I created a component resource based on the docs on https://www.pulumi.com/docs/intro/concepts/resources/components/. I call ctx.RegisterResourceOutputs at the end to register some outputs. When running pulumi up no outputs are displayed and no outputs are available according to pulumi stack output.

Steps to reproduce

Expected Behavior

I expected the outputs I register to be shown at the end of pulumi up.

Actual Behavior

No outputs seem to exist and are not displayed on the console.

Output of pulumi about

CLI
Version 3.46.1 Go Version go1.19.3 Go Compiler gc

Plugins NAME VERSION go unknown hcloud 1.10.1

Host
OS arch Version
Arch x86_64

This project is written in go: executable='/usr/bin/go' version='go version go1.19.4 linux/amd64'

Current Stack: prod

TYPE URN pulumi:pulumi:Stack urn:pulumi:prod::infra::pulumi:pulumi:Stack::infra-prod pulumi:providers:hcloud urn:pulumi:prod::infra::pulumi:providers:hcloud::provider hcloud:index/placementGroup:PlacementGroup urn:pulumi:prod::infra::hcloud:index/placementGroup:PlacementGroup::spread hcloud:index/sshKey:SshKey urn:pulumi:prod::infra::hcloud:index/sshKey:SshKey::laptop hcloud:index/sshKey:SshKey urn:pulumi:prod::infra::hcloud:index/sshKey:SshKey::desktop hcloud:index/firewall:Firewall urn:pulumi:prod::infra::hcloud:index/firewall:Firewall::firewall

Found no pending operations associated with prod

Backend
Name pulumi.com URL https://app.pulumi.com/daenney User daenney Organizations daenney

Dependencies: NAME VERSION github.com/pulumi/pulumi-hcloud/sdk 1.10.1 github.com/pulumi/pulumi/sdk/v3 3.44.2

Pulumi locates its logs in /tmp by default

Additional context

type Server struct {
    pulumi.ResourceState

    ipv4     *hcloud.PrimaryIp
    ipv6     *hcloud.PrimaryIp
    instance *hcloud.Server
}

func NewServer(ctx *pulumi.Context, name string, args *ServerArgs, opts ...pulumi.ResourceOption) (*Server, error) {

    server := &Server{}
    if err := ctx.RegisterComponentResource("internal:Server", name, server, opts...); err != nil {
        return nil, err
    }
    ... create some resources ...

    if err := ctx.RegisterResourceOutputs(server, pulumi.Map{
        "ipv4": pulumi.Map{
            "address": server.ipv4.IpAddress,
            "network": server.ipv4.IpNetwork,
            "id":      server.ipv4.ID(),
        },
        "ipv6": pulumi.Map{
            "address": server.ipv6.IpAddress,
            "network": server.ipv6.IpNetwork,
            "id":      server.ipv6.ID(),
        },
        "id": server.instance.ID(),
    }); err != nil {
        return server, err
    }

    return server, nil
}
$ pulumi up
Previewing update (prod)

View Live: https://app.pulumi.com/daenney/infra/prod/previews/<redacted>

     Type                          Name        Plan       
     pulumi:pulumi:Stack           infra-prod             
 +   └─ internal:Server            eu2         create     
 +      ├─ hcloud:index:PrimaryIp  eu2-ipv6    create     
 +      ├─ hcloud:index:PrimaryIp  eu2-ipv4    create     
 +      └─ hcloud:index:Server     eu2         create     

Resources:
    + 4 to create
    6 unchanged

Do you want to perform this update? yes
Updating (prod)

View Live: https://app.pulumi.com/daenney/infra/prod/updates/20

     Type                          Name        Status            
     pulumi:pulumi:Stack           infra-prod   (0.00s)          
 +   └─ internal:Server            eu2         created (21s)     
 +      ├─ hcloud:index:PrimaryIp  eu2-ipv6    created (1s)      
 +      ├─ hcloud:index:PrimaryIp  eu2-ipv4    created (1s)      
 +      └─ hcloud:index:Server     eu2         created (18s)     

Resources:
    + 4 created
    6 unchanged

Duration: 24s

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

daenney commented 1 year ago

Rereading a bunch of the documentation, I think this is caused by some confusion on my part. RegisterResourceOutputs is documented as:

Component resources can define their own output properties by using register_outputs . The Pulumi engine uses this information to display the logical outputs of the component resource and any changes to those outputs will be shown during an update.

This reads an awful lot like stack outputs, which is why I expected to see them in the result of pulumi up. That doesn't appear to be the case.

But even if I register the output of a resource and then change an input that should affect that output, I still don't get any output contrary to what the documentation suggests. So if I add a "retain": server.instance.RebuildProtection, to my pulumi.Map that is passed into RegisterResourceOutputs, create the server and then change my configuration to alter the value of RebuildProtection to false (it defaults to true in my component), I still don't get any output in the CLI.