https://pulumi.com logo
Title
f

few-yacht-11623

05/15/2022, 2:19 PM
Hi everyone, I’m just getting started trying out Pulumi with some basic state. I have an S3 bucket and a EB Environment defined in a single
index.ts
file and I’m trying to refactor this into multiple files/directories. However, I’m getting inconsistent import behavior once I split these files into different directories.
pulumi preview
will sometime show 0 changes, sometimes it will try to delete my EB environment that’s a few layers of imports deep. I put log statements in my files and it looks like sometimes it doesn’t import the file it’s defined in. 1. Are there any articles/docs on refactoring pulumi programs I can read? 2. Do files need to have an export to be processed for pulumi state? My EB env is just declared as a
const
variable without exporting anything, and I’m wondering if that might be part of my issue. 3. Does pulumi cache my input program in any way?
nevermind, it sounds like I am just hitting generic typescript/ecmascript issues with module loading. I must not understand the behavior when importing modules with no exports. I was using
export * from './subtree'
and I swapped those to
import './subtree'
and now it is working consistently
still any resources on factoring / organizing pulumi state would be helpful!
s

sparse-park-68967

05/16/2022, 1:29 PM
I assume you are asking about how to organize stacks? Some approaches are mentioned here: https://www.pulumi.com/docs/guides/organizing-projects-stacks/
f

few-yacht-11623

05/16/2022, 6:24 PM
I’m more interested in how to organize files within a single stack, really. Do most people just do one TS file per stack?
all of the examples on that page seem to show a single
.ts
file per stack
but I am imagining people would use shared TS utilities, and separate infrastructure into multiple files in a given stack. And that is the part I’m curious about
s

sparse-park-68967

05/16/2022, 6:38 PM
You have the freedom to organize the code the way you prefer and bring your code style over - lots of examples in Pulumi/examples repo use multiple files. For simple things single file is sufficient but for more complex environments I have seen lots of namespaces etc.