Hi, just wondering if there is a way to auto gener...
# typescript
b
Hi, just wondering if there is a way to auto generate typescript types for the config.
k
Which config? Everything I've encountered has types already
b
Your stacks config
k
Do you mean the stack output?
e.g.
export const x_name = resource.name;
b
I mean the stacks config, which u can set in the yaml file. Pulumi.stack.yaml
k
ah, i see now
I'm not aware of any way to gen a type from this (though there's proably an online tool)
What I do though, is hand craft a type and then require all the values into this and use it in a multi-stack
using a stack import
sorry, that may not be too helpful to your case
b
Does the cli validate the User provided types for the config
k
pretty much
hang on a sec and I'll get an example
Copy code
//StackConfig.ts

//...//
export type CommonConfig = {
  vNetCidr: string;
  numProp: number;
  secretValue: Output<any>;
  internalProp: string;
  //...//
}

//CommonConfig.ts
export = async () => {
  const config = new pulumi.Config();

  const out: Omit<CommonConfig, "internalProp"> = {
    vNetCidr: config.require("vNetCidr"),
    numProp: config.requireNumber("numProp"),
    secretValue: config.requireSecret("secretValue"),
  };
  return out;
}
basically, I have a config stack which only holds my config, then I import that into any stacks that require config settings
b
Thanks that code snippet definitely helped. I was trying to think of a way to import the whole config in a type by using adding the template type in config.require. But it's probably better to construct a hand crafted config object.
k
no worries, glad it helped a bit
it's not the best, i'd be interested in a better way
currently, to add a new config value, I have to edit it in 4 places, not very DRY at all 🙂
b
Four places, so the first is the yaml file, second is the config type, third would be requiring the new config value, what's the fourth one
k
In the stack reference I have to do the extremely similar function as to the config require
Copy code
appApiEndpoint: await stackRef.requireOutputValue("appApiEndpoint"),
appCallbackUrls: await stackRef.requireOutputValue("appCallbackUrls"),