RandomPassword panics in Go sdk
jaxxstorm opened this issue Β· comments
What happened?
import (
"github.com/pulumi/pulumi-random/sdk/v4/go/random"
)
adminPassword, err := random.NewRandomPassword(
ctx,
fmt.Sprintf("db-admin-password-%s-%s", args.Name, name),
&random.RandomPasswordArgs{
Length: pulumi.Int(64),
Lower: pulumi.Bool(true),
Number: pulumi.Bool(true),
Upper: pulumi.Bool(true),
Special: pulumi.Bool(true),
},
)
panic: applier's input parameters must be assignable from context.Context and interface {}
Steps to reproduce
Use
github.com/pulumi/pulumi-gcp/sdk/v5 v5.26.0
github.com/pulumi/pulumi-random/sdk/v4 v4.6.0
github.com/pulumi/pulumi-tls/sdk/v4 v4.0.0
github.com/pulumi/pulumi/sdk/v3 v3.32.1
Downgrading to
github.com/pulumi/pulumi-gcp/sdk/v5 v5.26.0
github.com/pulumi/pulumi-random/sdk/v4 v4.2.0 // older
github.com/pulumi/pulumi-tls/sdk/v4 v4.0.0
github.com/pulumi/pulumi/sdk/v3 v3.14.0 // older
Expected Behavior
No panic
Actual Behavior
Panic!
Versions used
No response
Additional context
No response
Contributing
Vote on this issue by adding a
To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).
@jkodroff @stack72 this looks somewhat similar to the pulumi-tls
fix rolled out yesterday. pulumi/pulumi-tls@e25a98a
What do you think?
@phillipedwards / @jaxxstorm I can no longer replicate this - is this now sorted?
Happy to close if you can't reproduce it
Yeah closing this as I can't reproduce it:
pulumi up
Previewing update (dev)
View Live: https://app.pulumi.com/stack72/tessting/dev/previews/13e99be6-c627-45b8-8ccf-27a27e6eb173
Type Name Plan
+ pulumi:pulumi:Stack tessting-dev create
+ ββ random:index:RandomPassword db-admin-password-test create
Outputs:
test: output<string>
Resources:
+ 2 to create
Do you want to perform this update? yes
Updating (dev)
View Live: https://app.pulumi.com/stack72/tessting/dev/updates/1
Type Name Status
+ pulumi:pulumi:Stack tessting-dev created
+ ββ random:index:RandomPassword db-admin-password-test created
Outputs:
test: [secret]
Resources:
+ 2 created
Duration: 5s
I have to reopen this. We got feedback on this from one of our customers. The customer was also so kind to provide us with some traces and logs on his side.
Will provide this internally.
I'm not sure the newly reported issue is actually related to this issue, but I'll leave some notes here.
The panic from the new report is:
panic: applier's input parameters must be assignable from context.Context and interface {}
goroutine 1 [running]:
github.com/pulumi/pulumi/sdk/v3/go/pulumi.checkApplier({0x103c87fa0?, 0x10403d8e8?}, {0x10407bca8, 0x103c8f860})
/Users/usernam/go/pkg/mod/github.com/pulumi/pulumi/sdk/v3@v3.44.3/go/pulumi/types.go:397 +0x324
github.com/pulumi/pulumi/sdk/v3/go/pulumi.(*OutputState).ApplyTWithContext(0x0, {0x104055ab8?, 0x140001ae048}, {0x103c87fa0?, 0x10403d8e8?})
/Users/usernam/go/pkg/mod/github.com/pulumi/pulumi/sdk/v3@v3.44.3/go/pulumi/types.go:470 +0x68
github.com/pulumi/pulumi/sdk/v3/go/pulumi.URNOutput.ToStringOutputWithContext({0x103858ad0?}, {0x104055ab8?, 0x140001ae048?})
/Users/usernam/go/pkg/mod/github.com/pulumi/pulumi/sdk/v3@v3.44.3/go/pulumi/types_builtins.go:4512 +0x34
github.com/pulumi/pulumi/sdk/v3/go/pulumi.URNOutput.ToStringOutput(...)
/Users/usernam/go/pkg/mod/github.com/pulumi/pulumi/sdk/v3@v3.44.3/go/pulumi/types_builtins.go:4508
github.com/pulumi/pulumi/sdk/v3/go/pulumi.Alias.collapseToURN({{0x0, 0x0}, {0x10406eaa0, 0x140005af7f0}, {0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}, ...}, ...)
/Users/usernam/go/pkg/mod/github.com/pulumi/pulumi/sdk/v3@v3.44.3/go/pulumi/alias.go:80 +0x108
github.com/pulumi/pulumi/sdk/v3/go/pulumi.(*Context).collapseAliases(0x103858ad0?, {0x140002dc100, 0x2, 0x23?}, {0x103858ad0, 0x2a}, {0x140003b6630, 0x23}, {0x104077b98?, 0x140005cc2a0?})
/Users/usernam/go/pkg/mod/github.com/pulumi/pulumi/sdk/v3@v3.44.3/go/pulumi/context.go:1004 +0x1d4
github.com/pulumi/pulumi/sdk/v3/go/pulumi.(*Context).registerResource(0x14000296420, {0x103858ad0, 0x2a}, {0x140003b6630, 0x23}, {0x104044260?, 0x140001d8840}, {0x104077648, 0x14000269d40}, 0x0, ...)
/Users/usernam/go/pkg/mod/github.com/pulumi/pulumi/sdk/v3@v3.44.3/go/pulumi/context.go:782 +0x3ac
github.com/pulumi/pulumi/sdk/v3/go/pulumi.(*Context).RegisterResource(...)
/Users/usernam/go/pkg/mod/github.com/pulumi/pulumi/sdk/v3@v3.44.3/go/pulumi/context.go:692
github.com/pulumi/pulumi-random/sdk/v4/go/random.NewRandomPassword(0x103e7d4a0?, {0x140003b6630?, 0x23?}, 0x140001d8840?, {0x140002ae6f0?, 0x3?, 0x3?})
/Users/usernam/go/pkg/mod/github.com/pulumi/pulumi-random/sdk/v4@v4.8.2/go/random/randomPassword.go:118 +0xa0
main.createAdminUser(0x103834360?, 0x1400042bb38, 0x140005cc2a0, {0x104055350?, 0x140005af360}, 0x1)
/Users/usernam/Developer/platform/k8s-pulumi-gcp/platform/sql/sql.go:346 +0x4d0
main.NewSQL(0x14000296420, 0x1400042bb38)
/Users/usernam/Developer/platform/k8s-pulumi-gcp/platform/sql/sql.go:174 +0x7d8
main.main.func1(0x14000296420)
/Users/usernam/Developer/platform/k8s-pulumi-gcp/platform/sql/main.go:90 +0xae4
github.com/pulumi/pulumi/sdk/v3/go/pulumi.RunWithContext(0x14000296420, 0x10403ef20)
/Users/usernam/go/pkg/mod/github.com/pulumi/pulumi/sdk/v3@v3.44.3/go/pulumi/run.go:120 +0x14c
github.com/pulumi/pulumi/sdk/v3/go/pulumi.runErrInner(0x140000021a0?, 0x10403d870, {0x0, 0x0, 0x1400008a768?})
/Users/usernam/go/pkg/mod/github.com/pulumi/pulumi/sdk/v3@v3.44.3/go/pulumi/run.go:96 +0x244
github.com/pulumi/pulumi/sdk/v3/go/pulumi.Run(0x1400008a768?, {0x0?, 0x1050887c8?, 0x140000021a0?})
/Users/usernam/go/pkg/mod/github.com/pulumi/pulumi/sdk/v3@v3.44.3/go/pulumi/run.go:48 +0x34
main.main()
/Users/usernam/Developer/platform/k8s-pulumi-gcp/platform/sql/main.go:16 +0x30
error: an unhandled error occurred: program exited with non-zero exit code: 2
This indicates an issue here:
https://github.com/pulumi/pulumi/blob/v3.44.3/sdk/go/pulumi/alias.go#LL80C11-L80C11
It appears that the parent URN is returning a URNOutput which is non-nil, but resolves to a non-URN value. It's not clear how that could be.
The code that triggered this that was shared was this:
adminPassword, err := random.NewRandomPassword(
ctx,
fmt.Sprintf("db-admin-password-%s-%s", args.Name, name),
&random.RandomPasswordArgs{
Length: pulumi.Int(64),
Lower: pulumi.Bool(true),
Number: pulumi.Bool(true),
Upper: pulumi.Bool(true),
Special: pulumi.Bool(true),
},
pulumi.Parent(db),
pulumi.AdditionalSecretOutputs([]string{"result"}),
pulumi.Aliases(append(
GetPostgresAlias(args.CreateAlias, "db-admin-password12"),
GetPostgresAlias(legacyNameAlias, fmt.Sprintf("db-admin-password-%s", args.Name))...,
)),
)
This does indeed have aliases
and parent
which appear to both be necessary to trigger the codepath that results in this panic (neither of which are in the repro in this issue above). It's still unclear though how the parent has this malformed URN.
Here is an attempted repro that includes the key elements that seem to be required - but unfortunately this still doesn't reproduce the panic reported above.
package main
import (
"fmt"
"github.com/pulumi/pulumi-random/sdk/v4/go/random"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
type SQL struct {
pulumi.ResourceState
AdminPwd pulumi.StringInput
NewAdminPwd pulumi.StringInput
}
func NewSQL(ctx *pulumi.Context, name string, opts ...pulumi.ResourceOption) (*SQL, error) {
myComponent := &SQL{}
err := ctx.RegisterComponentResource("pkg:index:MyComponent", name, myComponent, opts...)
if err != nil {
return nil, err
}
return myComponent, nil
}
func GetPostgresAlias(createAlias bool, oldAlias string) []pulumi.Alias {
if !createAlias {
return []pulumi.Alias{}
}
return []pulumi.Alias{{URN: nil}}
}
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
db, err := NewSQL(ctx, "db")
if err != nil {
return err
}
adminPassword, err := random.NewRandomPassword(
ctx,
fmt.Sprintf("db-admin-password-%s-%s", "test", "test"),
&random.RandomPasswordArgs{
Length: pulumi.Int(64),
Lower: pulumi.Bool(true),
Number: pulumi.Bool(true),
Upper: pulumi.Bool(true),
Special: pulumi.Bool(true),
},
pulumi.Parent(db),
pulumi.Aliases(append(
GetPostgresAlias(true, "db-admin-password12"),
GetPostgresAlias(true, "db-admin-password")...,
)),
)
if err != nil {
return err
}
ctx.Export("adminPassword", adminPassword.Result)
return nil
})
}
err := ctx.RegisterComponentResource("pkg:index:MyComponent", name, myComponent, opts...) if err != nil { return nil, err }
Removing these lines triggers the repro. It is ultimately a case where the parent's embedded ResourceState has not been initialized, and therefore has an invalid value for its internal URN
.
This was always invalid state for a parent resource, but it appears it didn't trigger this panic until the changes in pulumi/pulumi@e38876f. The upgrade that the user is doing was from a version of pulumi before this change to after it, which caused the panic to surface.
Ultimately there are two problems:
- The user code needs to use a valid parent resource (or no parent) - we validated that the user who hit this appears to be able to fix this by not parenting the resource (due to the existing aliases).
- The Pulumi Go SDK should "fail better" here - either fail early if a non-initialized resorucestate is used as a parent, or ensure that things that read URN don't fail if it is uninitialized (and return a useful default result).
I'll leave this open to track (2).
Closing this as a dupe of pulumi/pulumi#12138 since that's where the real issue here is.