I've been trying to find the answer of this question regarding the equivalent of Terraform modules in Pulumi, the closest answer is this link to this blog. Bear in mind that I'm a beginner for using Pulumi too.
With Terraform, you can create a git repository containing all of your modules, version it and pull it into various other git repositories by using source = "git@github.com:xyz"
. Terraform allows you also to turn On and Off resources based on conditionals such as regions, account number or environments for instance (with count
method for modules and resources).
Apparently Pulumi does not have this concept, looks like you need to duplicate your code in each repository or create a giant monolith repository containing all of your code. I'm also wondering what's the best practice for feature flags, turning On and Off resources for each of your specific stacks, what sort of conditionals you'll be using for this.
Thanks again for your highlights!
Broadly, you should create libraries in your language of choice and put reusable functions, classes, and components in there. For example, if you use TypeScript, you could create an NPM module (public or private) with any code that you want to reuse across projects and teams.
More specifically, if you are looking for a way to combine multiple resources into a reusable higher-level abstraction, you can implement it as a Component Resource. A component would accept inputs, instantiate a few resources in its constructor, and return output values. You can still package a component (or multiple components) as a reusable library.
Pulumi also allows you to create multi-language components, where you would implement it in one language but then publish it in all the supported languages for everyone to use. You can ship a multi-language component as a package in Pulumi registry to simplify discovery and installation. Read more in Pulumi Packages and multi-language Components and see other component in the Registry.