https://pulumi.com logo
#general
Title
# general
p

proud-pizza-80589

10/13/2022, 5:49 AM
Is there a way to reproduce the behaviour of Random for my own custom resources? I have a generated value that i later store in Vault but that i never want to regenerate. So how do i prevent
generateValue
to run on next runs?
Copy code
export class Example extends ComponentResource {

  constructor(name: string, opts?: ComponentResourceOptions) {
    super('example', name, {}, opts);

    const generated = somelib.generateValue();

    new Secret(
      name,
      {
        path: `somepath/${name}`,
        dataJson: 
          JSON.stringify(generated)
        
      },
      { parent: this, ignoreChanges: ['*'], protect: true }
    );
  }
}
q

quaint-salesmen-18327

10/13/2022, 7:44 AM
You generate the random value externally and feed it via configuration into your stack.
Copy code
$ program-to-generate-value | pulumi config set generatedValue --secret
Then in your program:
Copy code
const config = new pulumi.Config();
const generated = config.requireSecret('generatedValue');
p

proud-pizza-80589

10/13/2022, 7:46 AM
wanted to prevent that 😉 dynamic providers look like what i need https://www.pulumi.com/docs/intro/concepts/resources/dynamic-providers/
q

quaint-salesmen-18327

10/13/2022, 7:46 AM
I guess it depends on the kind of value you want to generate. 😉 It could also be that instead of a random value you could apply some kind of deterministic hash function on the inputs?
e

echoing-dinner-19531

10/13/2022, 8:58 AM
I mean you could just use the random provider inside your component resource?
But yes dynamic providers are a good way to do this if the random provider isn't sufficient.