This message was deleted.
s
This message was deleted.
b
different folders can have different Pulumi.yaml files
which signify different projects
f
No, same project
different stack
prod_infra_stack
prod_app_stack
b
so I'm not sure of the question
a stack is a representation of state and config
f
Sorry let me rephrase.
b
it's not the pulumi code itself
f
https://www.pulumi.com/docs/intro/concepts/stack/#stackreferences Mentions the ability to have separate code and stacks under the same project.
b
so a stack reference will allow you to take outputs from 1 stack and use in another
f
So you would have
MyProject/prod_infra
MyProject/prod_app
Two stacks
b
f
But how would you separate which code (say
index.ts
) runs during CI?
b
it's AWS based but the same principle applies
f
We use AWS, but I think you misunderstood.
I know how stack references work.
I am asking how to organize the code so I’d have two stacks on the same project one related to just setting up infra and other to build docker and push to k8.
Right now I can change stack, but I can’t tell this stack to run a different
index.ts
b
so you want 2 different stacks to operate different code within the same pulumi application?
in that case, you will need to use flags in your code
and then in stac, set flags about if code should run
f
I see.
Is it possible to do that in a single stack as well? Or would that destroy resources?
b
Copy code
const config = new pulumi.Config();
const isProd = config.require("isProd");

if (isProd) {
  // run these resources
} else {
  // run these resources
}
that will work fine for a specific stack
then in 1 stack, you would set isProd: true
and the other isProd: false
f
It’s not prod
Hold on.
b
I think you are taking my example too literally
it's a flag
it can be x: true
f
No, I get the flag concept.
I am asking if there is a distinction between conditionals between stacks or a single stack.
Like if I did that on a single stack, I’d assume some resources would be deleted.
b
correct
f
But since it runs a different stack, it would be fine since the backing state has no references to say VPC or EKS.
b
correct
f
Alright.
b
yes
personally, I'd be careful of this type of achitecture - it feels like there could be a more natural seam in your infra that separating to different projects that would give you a little tighter control over
f
I actually want to go away from that.
I want not to have multiple projects.
I’ll explain later.
b
ok
just please be careful about how you structure this and it should be good
f
So I could technically have two files.
app.ts
&
infra.ts
Import both of them dynamically based on conditions? inside
index.ts
Copy code
ts
import * as infra from  `infra.ts`
import * as app from  `app.ts`
const config = new pulumi.Config();
const isInfra = config.require("isInfra");

if (isInfra) {
  // run these resources
   infra()
   app()
} else {
   app()
  // run these resources
}
Something like that?
b
yup
f
But I still have to use stackreferences if
app()
calls need stuff like ARN and kubeconfig, etc?
b
not if they are in the same project
but you can if you are in the !isInfra section
f
But that’s my question here, like how would
app()
conditional access the vpc created in
infra()
if it’s running on the app stack without using stack references.
b
☝️
but you can if you are in the !isInfra section
f
can, but not must?
I inferred that I don’t need to and I can just access the VPC variable directly.
assuming they get exported.
b
you will need to for sure if you are in the !isInfra
f
Ok, so not can, but must 🙂
@broad-dog-22463 One final question since it was a bit unclear. You can not run different
index.ts
code between stacks, only between projects, correct?
like the
infra.yaml
can’t specify that it should run
infra.ts
and
app.yaml
can’t specify that it should run
app.ts
b
correct - our stack based config doesn't support entry points
FWIW, there's actually a good video on this that was published recently where our VP of eng described the scenario you are talking about -

https://www.youtube.com/watch?v=t_mLNzug2ho&ab_channel=Docker

f
Thanks! Will check it out
b
this will build localstack style on a local stack file and then a different set of infra when a different stack is selected