pulumi / pulumi-digitalocean

A DigitalOcean Pulumi resource package, providing multi-language access to DigitalOcean
Apache License 2.0
83 stars 13 forks source link

Cannot use 'dataBaseServer.ID()' (type IDOutput) as the type IntInputType #534

Closed ayumakesit closed 1 month ago

ayumakesit commented 1 year ago

What happened?

Following the example to create a firewall I’m trying to use the ID of the created droplet. The example: https://www.pulumi.com/registry/packages/digitalocean/api-docs/firewall/

I get the following error:

Cannot use 'dataBaseServer.ID()' (type IDOutput) as the type IntInputType does not implement 'IntInput' as some methods are missing:ToIntOutput() IntOutputToIntOutputWithContext(ctx context.Context) IntOutputToIntPtrOutput() IntPtrOutput…

Example

dataBaseServer, err := do.NewDroplet(ctx, name, &do.DropletArgs{
    Size:    pulumi.String("s-1vcpu-2gb"),
    Image:   pulumi.String("ubuntu-22-04-x64"),
    Region:  pulumi.String(region),
    VpcUuid: vpc.ID(),
})

if err != nil {
    return err
}

_, err = do.NewFirewall(ctx, "databaseFirewall", &do.FirewallArgs{
    DropletIds: pulumi.IntArray{
        dataBaseServer.ID(),
    },
    InboundRules: do.FirewallInboundRuleArray{},
    OutboundRules: do.FirewallOutboundRuleArray{},
})

Output of pulumi about

CLI Version 3.92.0 Go Version go1.21.3 Go Compiler gc

Plugins NAME VERSION digitalocean 4.23.0 go unknown

Host OS darwin Version 14.1 Arch arm64

Dependencies: NAME VERSION github.com/pulumi/pulumi-digitalocean/sdk/v4 4.23.0 github.com/pulumi/pulumi/sdk/v3 3.92.0

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

mikhailshilkov commented 1 year ago

Hi @ayumakesit

This is because resource IDs are strings in Pulumi, while DropletIds expects integers. Assuming dataBaseServer.ID() is in fact an integer, you should be able to convert it with something like

_, err = do.NewFirewall(ctx, "databaseFirewall", &do.FirewallArgs{
    DropletIds: pulumi.IntArray{
        dataBaseServer.ID().ToStringOutput().ApplyT(func(id string) int {
            v, _ := strconv.Atoi(id)
            return v
        }).(pulumi.IntOutput),
    },
    InboundRules: do.FirewallInboundRuleArray{},
    OutboundRules: do.FirewallOutboundRuleArray{},
})

A similar issue for TypeScript: https://github.com/pulumi/pulumi-digitalocean/issues/81

Let me know if this helps.

ayumakesit commented 1 year ago

Hi @mikhailshilkov, thank you for the response :)

I already converted it:

_, err = do.NewFirewall(ctx, "databaseFirewall", &do.FirewallArgs{
    DropletIds: pulumi.IntArray{
        dataBaseServer.ID().ApplyT(strconv.Atoi).(pulumi.IntOutput),
    },
    InboundRules: do.FirewallInboundRuleArray{
        &do.FirewallInboundRuleArgs{
            Protocol:  pulumi.String("tcp"),
            PortRange: pulumi.String("22"),
        },
    },
    OutboundRules: do.FirewallOutboundRuleArray{},
})

For newbies like me, it would be very helpful if the documentation could show the right way ;)

mikhailshilkov commented 1 year ago

Great to hear you are unblocked! I'll leave the issue open to track fixing the example.

mikhailshilkov commented 12 months ago

Upstream pu/pu issue: https://github.com/pulumi/pulumi/issues/9841

mjeffryes commented 1 month ago

Tracked by #600