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

lemon-monkey-228

10/01/2021, 2:38 PM
Just wondering if there's a way to share config between each of the pulumi project's stacks
b

billowy-army-68599

10/01/2021, 3:46 PM
We don't have a mechanism for this yet, but you can of course Marshall your config yourself manually if needed from a file
s

steep-toddler-94095

10/01/2021, 5:27 PM
i depend minimally on the
Pulumi.stackname.yaml
files and instead have all configurations as typed TS objects. The only things I put in the yaml files are secrets, default providers, and a variable that allows the TS code to determine which config object to choose (usually a var called
environment
). Since you're allowed to use the full power of your language for configs, questions like "is there a way to share config between each of the pulumi project's stacks" have a trivial solution.
l

lemon-monkey-228

10/01/2021, 7:38 PM
Yeah, my normal pattern is to have
Copy code
types.ts
config.ts
index.ts
Where config.ts just creates a statically typed config object that I use in the rest of my app (and I pull from pulumi config here where required)
I also pull some secrets directly from files instead of the pulumi stack
I guess I'll just share a single TS file with shared config (and encrypt it in the repo like we do for other secrets, if it ends up containing secrets)
Only thing I'm not sure how to do, is to share provider config like
kubernetes:namespace
without manually setting a provider for all resources
b

busy-magazine-6225

11/01/2021, 12:27 AM
@colossal-australia-65039 @steep-toddler-94095 I don’t suppose you have any repo’s with an example for your configuration? I’m trying to figure out how to tie all that together and am having issues I’ve created a default.ts and env-dev.ts inside of my /src/config. I want to be able to declare values in both and have them get merged. I then want to utilize this combined result inside index.ts. The issue I’m having is referencing that merged result dynamically. I need to import the config from index.ts but cannot do so dynamically as imports have to be static. Any ideas?
I suppose I could load all of the available configs and then just choose between them based off a pulumi stack config value
s

steep-toddler-94095

11/01/2021, 7:08 PM
hey sorry forgot to respond to this. I don't have a public repo to show, but I'll describe in a bit more detail what I do 1. For each stack, have a
projectname:environment: <dev|staging|production>
config value 2. Have a
config.ts
file that is basically a ternary
Copy code
import {devConfig} from "./devConfig"
import {stagingConfig} from "./stagingConfig"
import {productionConfig} from "./productionConfig"
import * as pulumi from "@pulumi/pulumi"

const pulumiConfig = new pulumi.Config()
const config: Config = pulumiConfig.require("environment") == "dev" ?
    devConfig
  : pulumiConfig.require("environment") == "staging" ?
    stagingConfig
  : pulumiConfig.require("environment") == "production" ?
    productionConfig
  : {} as Config // Not the most "elegant" solution but it's simple and it works well enough
3. Then in those 3 config files I just have my separate configs. If your situation requires DRYing up a lot of configs, it's not difficult to extends this pattern to do that.
b

busy-magazine-6225

11/02/2021, 5:32 AM
Thanks! I ended up doing a switch that also allowed me to utilize a default.ts that gets merged with the environment configs, that way I can have some default values that can get overwritten at the environment level
👍 1