How to understand a Pulumi (TypeScript) codebase
Pulumi describes infrastructure in general-purpose code. The program creates resource objects, and Pulumi works out dependencies from how outputs of one resource feed into inputs of another. Values that are only known after deployment are `Output`s, which is the key concept for reading the code.
How to tell it's Pulumi (TypeScript)
Pulumi.yamlandPulumi.<stack>.yamlfiles@pulumi/pulumiplus provider packages such as@pulumi/aws- Calls like
new aws.s3.Bucket(...),pulumi.interpolateand.apply(...)
Where things usually live
- Pulumi.yaml
- Project name and runtime.
- Pulumi.<stack>.yaml
- Per-stack config values, including encrypted secrets.
- index.ts
- The program: resources and exported outputs.
- components/
ComponentResourceclasses that group related resources.
Conventions, not rules. Real projects rename and move things, so confirm against the repository.
Where to start reading
index.tsand its exports- Stack config files, to see how environments differ
How a request moves through the code
pulumi upruns the program for the selected stack.- Resources are registered; outputs passed as inputs create dependencies.
- Pulumi compares desired state with the stack's state and plans changes.
- Exported outputs are shown after deploy and can be read by other stacks.
Questions to ask about the repository
- Which resources does this program create, grouped by component?
- Which config values differ per stack?
- Which outputs are exported, and who consumes them?
What trips people up
- An
Outputis not a plain value; using it in a template string withoutinterpolateorapplygives a placeholder. - Renaming a resource's logical name replaces it unless an alias is added.