https://pulumi.com logo
#typescript
Title
# typescript
b

bitter-australia-87528

06/03/2021, 7:52 AM
Hi, just wondering if there is a way to auto generate typescript types for the config.
k

kind-mechanic-53546

06/03/2021, 10:11 PM
Which config? Everything I've encountered has types already
b

bitter-australia-87528

06/04/2021, 3:14 AM
Your stacks config
k

kind-mechanic-53546

06/04/2021, 3:16 AM
Do you mean the stack output?
e.g.
export const x_name = resource.name;
b

bitter-australia-87528

06/04/2021, 3:24 AM
I mean the stacks config, which u can set in the yaml file. Pulumi.stack.yaml
k

kind-mechanic-53546

06/04/2021, 3:25 AM
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

bitter-australia-87528

06/04/2021, 3:27 AM
Does the cli validate the User provided types for the config
k

kind-mechanic-53546

06/04/2021, 3:28 AM
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

bitter-australia-87528

06/04/2021, 3:50 AM
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

kind-mechanic-53546

06/04/2021, 3:51 AM
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

bitter-australia-87528

06/04/2021, 8:51 AM
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

kind-mechanic-53546

06/04/2021, 11:46 PM
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"),