What are some of the best practices you use when d...
# general
s
What are some of the best practices you use when defining stacks that are substantially different based on environments (e.g. dev/stage/prod)?
For example, I have an
AuthStack
that creates a Cognito User Pool and related resources (App Clients, domains, etc).
In this example, my
prod
stage looks very different from my
dev
stage in terms of resources created
prod
, I may have dozens of App Clients and Domains associated with my User Pool. In
dev
, I may just create a single User Pool with a single App Client.
The amount of IaC needed to create these resources is rather verbose, and goes beyond swapping out a configuration value based on stage
I could use a single stack to organize all of this, but I envision it growing rather unwieldy with lots of conditional logic around the stage. This feels like a code smell
t
I've started to have extremely granular stacks
esp with the new functional stack stuff it's really easy to have a lot of small stacks. Then each stack has conditional code for the different envs, it's annoying but more manageable when the stacks are smaller
but of course the ideal is you avoid needing conditions all together but not always possible
s
Yeah, I'm finding the stage conditions to be tricky to avoid here.
maybe I'll start with a big 'ol stack and feel the pain first, then refactor. After all, the resources created in AWS will be the same. This is more a question of good code hygiene within my constructs
d
new functional stack stuff
@thdxr, can you expand here?
t
we haven't officially released it yet, working on a bunch of docs but I left an example here: https://serverless-stack.slack.com/archives/C01JVDJQU2C/p1646951175298129?thread_ts=1646950522.278839&cid=C01JVDJQU2C
t
It's a tough one. I guess passing in config to the stack declared in
index.js
is possibly an option? Perhaps pull in values from som sort of config module or something using
nconf
🤔