https://pulumi.com logo
Title
p

powerful-lighter-63321

04/08/2023, 7:20 AM
May be just a silly question: I'm using go for the infrastructure but as of now I feel very confused about the many casts from one Output to another Input. Before I used terraform and changed over. Which seems to be a real pain. In terraform I haven't the ability to use functions and loops and so on. What's a real cool thing in pulumi. But this trying to cast from one xxxoutput to another or to an xxxinput is a real pain. It slows me really down... Even the examples in the documentation are failing when not explicitly casting from one to another type... Do I miss something?
m

melodic-tomato-39005

04/08/2023, 1:58 PM
In most cases, you shouldn’t need to cast from Output to Input, you can just directly use the Output as Input. That’s because Input is defined as
type Input = T | Promise<T> | OutputInstance<T>;
[Input] is a property input for a resource. It may be a promptly available T, a promise for one, or the output from a existing Resource.
https://www.pulumi.com/docs/reference/pkg/nodejs/pulumi/pulumi/#Input
s

salmon-account-74572

04/10/2023, 2:04 PM
As a former Terraform user who switched to Pulumi (and who prefers to use Pulumi with Go), I will say that Go’s strict type system does make things a tad more challenging at times. For example, in most cases you need to use
pulumi.String()
or
<http://pulumi.Int|pulumi.Int>()
when specifying a property value. If you find cases where the documentation is incorrect (perhaps missing a type or specifying the wrong type), please file an issue and let us know! We want the docs to be as accurate and as helpful as possible. In the meantime, is there anything we can specifically help with?
p

powerful-lighter-63321

04/11/2023, 6:40 AM
It might be related to the pulumi-hcloud sdk for golang. I use it much and even the example in the docs did't work properly:
package main
import (
"<http://github.com/pulumi/pulumi-hcloud/sdk/go/hcloud|github.com/pulumi/pulumi-hcloud/sdk/go/hcloud>"
"<http://github.com/pulumi/pulumi/sdk/v3/go/pulumi|github.com/pulumi/pulumi/sdk/v3/go/pulumi>"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
mynet, err := hcloud.NewNetwork(ctx, "mynet", &hcloud.NetworkArgs{
IpRange: pulumi.String("10.0.0.0/8"),
})
if err != nil {
return err
}
_, err = hcloud.NewNetworkSubnet(ctx, "foonet", &hcloud.NetworkSubnetArgs{
NetworkId:   mynet.ID(),
Type:        pulumi.String("cloud"),
NetworkZone: pulumi.String("eu-central"),
IpRange:     pulumi.String("10.0.1.0/24"),
})
if err != nil {
return err
}
return nil
})
}
The mynet.ID() which should be used here can't be used and have to be casted in from IDOutput to IntInput.
s

salmon-account-74572

04/11/2023, 12:24 PM
Ah, yeah, AIUI that indicates an issue/limitation with the provider/SDK in use. I’d file an issue in https://github.com/pulumi/pulumi-hcloud.