<@U87DZN4MT> or anyone else, what approach would ...
# general
s
@bitter-oil-46081 or anyone else, what approach would you recommend to break a relatively long project into modules (I.E.: a module for networking, one for db, one for functions… and so on)?
b
Just so I understand the question - Are you wanting to take an existing pulumi program that deploys a bunch of related infrastructure and just break the program up into a set of modules (but you still run a single
pulumi up
command to update the entire thing) or are you looking to try to break your existing project into a bunch of smaller stacks (one for the networking layer, one for the db, etc)?
s
The first option. Like terraform, where you have a bunch of modules which you call in your root main.tf and then launch them together
b
Sorry for the delay in responding. There are two approaches here: 1) Move individual pieces of infrastructure into seperate modules and export interesting types for use by other modules. We do this a bunch in our own infrastructure (for example for some of our services we have a
network
module which creates a VPC, two subnets, an internet gateway and route table and route table assoications, but only exports the vpc, array of subnets and internet gateway. Then in other modules we do things like
import { vpc } from "../network";
This lets you structure your code in a reasonable way, and control what you expose externally. The next step you could consider taking would be to take these modules and consider wrapping all their resources in a component (this would mean that the display you see in the CLI would group logically related resources together, under the parent component) and then export and instance of component itself from the module. We find most folks will just start with one, to get good code organization. As you move to (2) you will need to make use of the
aliases
feature to ensure when you start taking existing infrastructure and setting its parent, you don't cause replaces to happen.
Is that the sort of guidance you are are looking for?
s
Will get back to this at a later date @bitter-oil-46081. Have to wrap up a few other things first… thanks nonetheless
Hi @bitter-oil-46081, I’m back on this matter. Do you have any demos?