https://serverless-stack.com/ logo
#sst
Title
# sst
a

Adrián Mouly

09/07/2021, 3:30 AM
Hey guys, looking for opinions/ideas here… I have some stacks which are “application related”, which are mostly feature-focused, and those rely on some foundational components created outside of SST, and managed from a single legacy SLS project. Those “shared resources” are the VPC, VPN, SecGroup, etc … So I’m thinking to migrate this old-SLS project into SST/CDK, but keeping it separated from my feature-based SST project. The reason is those foundational components I don’t want to be re-created on every PR, or created every time a developer does a local deployment. I want to keep them kind of outside the development flow, and create them only once. What you guys think? should I host these in a separated repo? If I have multiple accounts, one for each environment (dev, stage, prod, etc), I’m planning to share the same VPC/VPN/SecGrousp with every developer over
dev
for local development and PRs. Of course each developer is going to have their own stage. Thoughts? 🙂
s

Simon Reilly

09/07/2021, 8:21 AM
I am working through something similar at the minute, but with sls framework. Could you evaluate the stage in the shared-resources stack to default to dev; and the stage in the application stack to be either pr number, or username. Then, you can still pass around an exported prop e.g. resourceStack.vpc, can be passed into application stacks. And this remains one multistack set application?
f

Frank

09/07/2021, 7:32 PM
Yeah agreed with @Simon Reilly. While reading CDK’s source code, I saw they used the
getOrCreate
pattern. And I liked it. So in this case, ur core stack can look like this:
Copy code
if (stage === "dev-main") {
  this.vpc = new ec2.Vpc(...)
}
else if (stage.startsWith ("dev-")) {
  this.vpc = ec2.Vpc.lookup(...)
}
And
this.vpc
can be passed to other stacks.
a

Adrián Mouly

09/08/2021, 1:03 AM
Yeah could be, conditional resources.
But I’m worried if those resources gets deleted too.
How I can prevent that?
For example, developers are going to run
start
and
remove
from their local, and I don’t want to delete VPN/VPC for example.
f

Frank

09/08/2021, 2:13 AM
U mean by mistake right? Ie. in the example above, a user run
sst remove --stage de-main
. Is that what you mean?
a

Adrián Mouly

09/08/2021, 2:20 AM
No, user removing all their stuff with
sst remove
I mean, today I deploy all the stacks, for each dev.
Because I have like 7 or 8 microservices, one has their own stack + some shared stuff.
When a developer deploys, it deploys all of it…. and the same with remove.
But how I can control that when my stacks also have more stuff?
Not sure what to do yet.
Possibly the safest solution is to create another sst app.
f

Frank

09/08/2021, 2:39 AM
Just to clarify, in the above example, if user runs
sst remove --stage dev-joe
, the VPC won’t be removed. The core stack will only get removed by
sst remove --stage dev-main
.
a

Adrián Mouly

09/08/2021, 2:40 AM
I see, sorry, miss-understood.