`RandomBytes` resource broken in nodejs runtime
mattfysh opened this issue · comments
What happened?
Wrote a new stack program with a single index.ts to show that the @pulumi/pulumi
package resource RandomBytes
is not working. Received error:
Diagnostics:
pulumi:pulumi:Stack (delme-dev):
panic: reflect: call of reflect.Value.MethodByName on zero Value
goroutine 58 [running]:
reflect.Value.MethodByName({0x0?, 0x0?, 0x140003e2610?}, {0x104c4b1ca?, 0x1400068e100?})
/opt/hostedtoolcache/go/1.21.4/x64/src/reflect/value.go:2047 +0x114
github.com/pulumi/pulumi-terraform-bridge/pf/internal/pfutils.hasMethod(...)
/home/runner/go/pkg/mod/github.com/pulumi/pulumi-terraform-bridge/pf@v0.21.0/internal/pfutils/reflector.go:63
github.com/pulumi/pulumi-terraform-bridge/pf/internal/pfutils.extractNestedAttributes({0x0?, 0x0?})
/home/runner/go/pkg/mod/github.com/pulumi/pulumi-terraform-bridge/pf@v0.21.0/internal/pfutils/reflector.go:26 +0xa8
github.com/pulumi/pulumi-terraform-bridge/pf/internal/pfutils.FromAttrLike(...)
/home/runner/go/pkg/mod/github.com/pulumi/pulumi-terraform-bridge/pf@v0.21.0/internal/pfutils/attr.go:68
github.com/pulumi/pulumi-terraform-bridge/pf/internal/pfutils.(*schemaAdapter[...]).AttributeAtPath(0x0?, {0x105152cb8?, 0x14000495c20?}, {{0x140003e2590?, 0x104ef41a0?, 0x140006d4f01?}})
/home/runner/go/pkg/mod/github.com/pulumi/pulumi-terraform-bridge/pf@v0.21.0/internal/pfutils/schema.go:120 +0x1b0
github.com/pulumi/pulumi-terraform-bridge/pf/tfbridge.newIDExtractor({0x105152cb8, 0x14000495c20}, {0x14000132ae0, 0xc}, {0x10515a2f0, 0x14000137720})
/home/runner/go/pkg/mod/github.com/pulumi/pulumi-terraform-bridge/pf@v0.21.0/tfbridge/ids.go:39 +0xac
github.com/pulumi/pulumi-terraform-bridge/pf/tfbridge.(*provider).resourceHandle(0x140001c7600, {0x105152cb8, 0x14000495c20}, {0x140006a4100?, 0x104e33d40?})
/home/runner/go/pkg/mod/github.com/pulumi/pulumi-terraform-bridge/pf@v0.21.0/tfbridge/provider_resources.go:56 +0xbc
github.com/pulumi/pulumi-terraform-bridge/pf/tfbridge.(*provider).CheckWithContext(0x140001c7600, {0x105152cb8?, 0x14000494e70?}, {0x140006a4100, 0x40}, 0x104ef3b20?, 0x140006d56a8?, 0x3c?, {0x1400044a000, 0x20, ...})
/home/runner/go/pkg/mod/github.com/pulumi/pulumi-terraform-bridge/pf@v0.21.0/tfbridge/provider_check.go:44 +0x198
github.com/pulumi/pulumi-terraform-bridge/pf/internal/plugin.(*providerServer).Check(0x14000494600, {0x105152cb8, 0x14000494e70}, 0x140004b0600)
/home/runner/go/pkg/mod/github.com/pulumi/pulumi-terraform-bridge/pf@v0.21.0/internal/plugin/provider_server.go:295 +0x184
github.com/pulumi/pulumi/sdk/v3/proto/go._ResourceProvider_Check_Handler.func1({0x105152cb8, 0x14000494e70}, {0x10507d680?, 0x140004b0600})
/home/runner/go/pkg/mod/github.com/pulumi/pulumi/sdk/v3@v3.96.2/proto/go/provider_grpc.pb.go:557 +0x74
github.com/grpc-ecosystem/grpc-opentracing/go/otgrpc.OpenTracingServerInterceptor.func1({0x105152cb8, 0x14000494990}, {0x10507d680, 0x140004b0600}, 0x1400068e060, 0x140003d0150)
/home/runner/go/pkg/mod/github.com/grpc-ecosystem/grpc-opentracing@v0.0.0-20180507213350-8e809c8a8645/go/otgrpc/server.go:57 +0x2e8
github.com/pulumi/pulumi/sdk/v3/proto/go._ResourceProvider_Check_Handler({0x105103240?, 0x14000494600}, {0x105152cb8, 0x14000494990}, 0x14000192200, 0x1400068f060)
/home/runner/go/pkg/mod/github.com/pulumi/pulumi/sdk/v3@v3.96.2/proto/go/provider_grpc.pb.go:559 +0x12c
google.golang.org/grpc.(*Server).processUnaryRPC(0x1400011e000, {0x105152cb8, 0x14000494570}, {0x10515c580, 0x1400033b380}, 0x1400037ab40, 0x14000494690, 0x105a05510, 0x0)
/home/runner/go/pkg/mod/google.golang.org/grpc@v1.59.0/server.go:1343 +0xb8c
google.golang.org/grpc.(*Server).handleStream(0x1400011e000, {0x10515c580, 0x1400033b380}, 0x1400037ab40)
/home/runner/go/pkg/mod/google.golang.org/grpc@v1.59.0/server.go:1737 +0x988
google.golang.org/grpc.(*Server).serveStreams.func1.1()
/home/runner/go/pkg/mod/google.golang.org/grpc@v1.59.0/server.go:986 +0x88
created by google.golang.org/grpc.(*Server).serveStreams.func1 in goroutine 56
/home/runner/go/pkg/mod/google.golang.org/grpc@v1.59.0/server.go:997 +0x160
random:index:RandomBytes (xyz):
error: error reading from server: EOF
Example
import * as random from '@pulumi/random'
const rnd = new random.RandomBytes('xyz', { length: 32 })
export const hex = rnd.hex
Output of pulumi about
CLI
Version 3.101.1
Go Version go1.21.6
Go Compiler gc
Plugins
NAME VERSION
nodejs unknown
random 4.15.0
Host
OS darwin
Version 14.2.1
Arch arm64
This project is written in nodejs: executable='/opt/homebrew/bin/node' version='v21.5.0'
Current Stack: <snip>
Found no resources associated with dev
Found no pending operations associated with dev
Backend
Name pulumi.com
URL <snip>
User <snip>
Organizations <snip>
Token type personal
Dependencies:
NAME VERSION
@pulumi/random 4.15.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).
Hi @mattfysh. Thanks for letting us know about the issue. I am able to repro. We'll take a look shortly.
Looking briefly, the random.RandomBytes resource does not have an "id" attribute in the schema. Pulumi assumes the existence of this attribute but unfortunately due to bugs in error handling this did not get surfaced at build time nor indeed was it surfaced at runtime in a helpful way. Looking at the implementation code for the resource they have something like this:
state.Base64 = types.StringValue(req.ID)
So it is probably OK to equate some of the structural attributes like the base64 random string with identity for these resources. Having a look at what it would take to support this in the bridge quickly.
This should be fixed in https://github.com/pulumi/pulumi-random/tree/v4.15.1 ! Thank you for reporting.
Thank you for the very fast turnaround :)
Hi there, it seems there is an issue now with saving the snapshot. Previous while I was waiting for the fix I was using:
const rsc = pulumi.output('apikey-tmp')
Which I've now tried replacing with:
const rnd = new random.RandomBytes(`apikey-${client}`, { length: 32 })
const rsc = pulumi.interpolate`prefix_${rnd.hex}`
However when I run the deployment, I get this error:
error: resource complete event returned an error: failed to save snapshot:
.pulumi/stacks/project/stack: snapshot integrity failure; it was already written, but is invalid
(backup available at .pulumi/stacks/project/stack.json.bak): resource
urn:pulumi:stack::project::command:local:Command::bundle dependency
urn:pulumi:stack::project::random:index/randomBytes:RandomBytes::apikey-client
refers to missing resource
my guess is that the provider snapshotting is not working because it doesn't appear to be writing the entry into the stack state before dependencies are being written (hence the missing reference error)
Reverting back to the hard-coded static string works for now
Scratch that, it's a user issue ;) I'm using the automation API and was creating the resource outside of the inline program