I'm wondering if there a pulumi native solution to...
# general
t
I'm wondering if there a pulumi native solution to the following problem: • I have blue/green deployment set up using s3 buckets for a static website
green_bucket
for green builds and
main_bucket
for the live app • I have provisioned appropriate long-lived infra for this, Lambda@Edge, certs etc. • Now I want the following behaviour ◦ When i run
pulumi up
it assumes a green build, and places my app files (
/dist/app-green/...
) into the
green_bucket
◦ When I run
BLUE_GREEN_CONTEXT=blue pulumi up
I want the files from
/dist/app/..
to go into the
main_bucket
Now the problem is that because pulumi is essentially using GitOps here, the
BLUE_GREEN_CONTEXT=blue
will conditionally cause S3 objects to be deleted . e.g when I run
pulumi up
any conditional logic I ahve in my pulumi file to put the content into the green bucket, will now cause the blue bucket to be delete
Copy code
if greenBuild
s3.Object(green)
elsse
s3.Oject(blue)
I don;'t see any way of solving this using pulumi s3.objects, and i am leaning towards just using aws cli to deploy
l
Hey @thousands-window-76079. I think your assessment is correct, yes. There are a few options that I can see though: • Use the AWS CLI as you suggest. You could use
@pulumi/command
to wrap it, though with this being a resource you might still have issues. • Use two different Pulumi stacks (e.g.
blue
and
green
). Then in
Pulumi.blue.yaml
you could configure the bucket name as
main_bucket
and in
Pulumi.green.yaml
the
green_bucket
. Then rather than bringing up one stack with conditional elements, you are bringing up the same stack with two different configurations. • Use Pulumi Automation to run the "unconditional" bit of the stack (bring up the buckets, link everything together etc.) then use the AWS SDK in your language of choice to do "the last bit" of actually pushing the relevant objects to the right place.
t
hi @lively-crayon-44649 thanks for your reply! I like your second point actually, but my issue is that I don't want a second CF distribution, etc. for each stack - so i would have to split up the pulumi project into "base blue green infra" and then the actual "app code" project but thats definetly something to think about, because i may end up having other apps that need to share this kind of infrastructure anyway
I also wasn't aware of
pulumi/command
I will look into that
l
It really depends how complicated you want to make it, but I think some sort of separation could be beneficial. Whether that's an "environment" stack (unconditional things, CF distribution, etc.) and the "application" stack(s) -- blue and green, or just separating the single program into two bits (one of which is more
command
or using automation to run non-Pulumi code), that would be my approach.
t
yeah i want it to be super simple, i think i will go with the command based approach for the S3 deployment Thanks for your help!
l
👍 No worries!