This is more of a code organization question (in G...
# general
b
This is more of a code organization question (in Go in this case) - is there a common pattern for how to organize the Pulumi code? Specifically, I’m managing quite a few Kubernetes resources, so everything is quite verbose, probably a couple of thousand lines of code. Typically I’d break different parts into functions (and maybe eventually a component resource), but they also have dependencies between them. As such, I’d have to ensure my functions return the created resources (which may be several in “function”) and also take in all the inputs they need. That’s a lot of overhead relative to just putting everything “inline/procedurally” in a single function. I’m just curious how folks manage this in terms of returning resources and passing them in dependencies between different parts.
To give a concrete example, I have a
Namespace
object I create and then use it in most resource creation (I know I could use a provider for this, but let’s say there is a reason I don’t for now).
Another example would be that I create a database in Postgres and a user to use that database, and I want to be able to use both the database name and the credentials in a bunch of places.
g
We're a few weeks into our migration over to Pulumi, and we're using a similar pattern in Golang. One thing we did was break out our infra into multiple Pulumi projects, and then use
StackReference
to import resources across project boundaries. To manage resource dependencies inside the same project, we're defining higher level
struct
types to encapsulate and group resources logically, and pass those structs around. This keeps our functions simpler and prevents parameter bloat.
b
Thanks @green-musician-49057 - good to hear from other experiences. Using
StackReference
makes sense for other stacks, and no issue with that, it’s more the second case you mentioned within the same project/stack, just how to manage the various resources.
g
👍