Description
What happened?
I tried to follow the docs to create a custom resource (to generate a password and its hash), but the outputs are always undefined
. I figured out that this is a bug caused by the class member definitions, as removing them make it work.
Expected Behavior
It should have worked on the first try. I closely followed https://www.pulumi.com/docs/intro/concepts/resources/dynamic-providers/#dynamic-resource-outputs.
Steps to reproduce
Original code:
import * as pulumi from "@pulumi/pulumi";
import { strict as assert } from "node:assert";
import * as crypto from "node:crypto";
const _hashedPasswordProvider: pulumi.dynamic.ResourceProvider = {
async create (inputs: {length: number}) {
const password = "dummy";
const hashedPassword = "my-super-pass-hashed-with-unique-salt";
return { id: crypto.randomUUID(), outs: { password, hashedPassword } };
}
};
class HashedPasswordResource extends pulumi.dynamic.Resource {
public readonly password!: pulumi.Output<string>;
public readonly hashedPassword!: pulumi.Output<string>;
constructor (name: string, props: {length: pulumi.Input<number>}, opts?: pulumi.CustomResourceOptions) {
const innerOpts = pulumi.mergeOptions(opts, { additionalSecretOutputs: ["password"] });
const innerProps = {password: undefined, hashedPassword: undefined, ...props};
super(_hashedPasswordProvider, name, innerProps, innerOpts);
}
}
function main() {
const botUsername = "robotsatan";
const botPassword = new HashedPasswordResource("robotsatan-password", { length: 30 });
// kaboom
assert.notEqual(botPassword.password, undefined);
assert.notEqual(botPassword.hashedPassword, undefined);
}
Diff to make it work:
- public readonly password!: pulumi.Output<string>;
- public readonly hashedPassword!: pulumi.Output<string>;
- const botPassword = new HashedPasswordResource("robotml-password", { length: 30 });
+ const botPassword = <any>new HashedPasswordResource("robotml-password", { length: 30 });
Output of pulumi about
CLI
Version 3.54.0
Go Version go1.20
Go Compiler gc
Plugins
NAME VERSION
nodejs unknown
Host
OS arch
Version 22.0.2
Arch x86_64
This project is written in nodejs: executable='/usr/bin/node' version='v19.5.0'
my package-lock.json says I have node_modules/@pulumi/pulumi
version": "3.54.0",
Additional context
Shout-out to the poor souls @ pulumi/pulumi#2931
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).
EDIT
Ok, this stuff is VERY freaking unstable.
I changed my resource to return Buffer.from(hash).toString('base64');
instead of hash
=> it started returning undefined
again until I renamed my resource !
Metadata
Metadata
Assignees
Type
Projects
Status