Thanks for the kind words. Unsure if this is exactly what you’re looking for, but here are some thoughts.
You can deploy only the specific stacks with terraspace up
. Examples:
TS_ENV=dev terraspace up video-generator
TS_ENV=prod terraspace up db
TS_ENV=prod terraspace up video-generator
TS_ENV=prod terraspace up web-app
So don’t deploy for the other web-app
and video-generator
for TS_ENV=dev
.
If you’re leveraging terraspace all up
, then you can specify the stacks to use.
TS_ENV=dev terraspace all up video-generator
TS_ENV=prod terraspace all up db video-generator web-app
If you would like to just call terraspace all up
without worrying about specifying the stacks. Maybe use the all.ignore_stacks
settings. Docs: https://terraspace.cloud/docs/config/reference/ Something like:
config/app.rb
Terraspace.configure do |config|
ignore_stacks = Terraspace.env == "dev" ? ["db", "web-app"] : []
config.all.ignore_stacks = ignore_stacks
end
Then terraspace all
can be blindly called:
TS_ENV=dev terraspace all up # only deploy video-generator
TS_ENV=prod terraspace all up # will deploy all stacks
In looking at this, added an all.include_stacks
option also. See: https://github.com/boltops-tools/terraspace/pull/85
Maybe a wrapper script also is simpler and more straightforward. Something like:
ts.sh
#!/bin/bash
if [ "$TS_ENV" == "dev" ]; then
terraspace all up video-generator
else
terraspace all up db video-generator web-app
fi
Also, if you want an additional safeguard to ensure that the wrong stack doesn’t get called an env, you can always add a snippet of ERB at the top of your stack main.tf. Something like:
app/stacks/db/main.tf
<% raise "shouldnt be called in this env: #{Terraspace.env} if Terraspace.env == "dev" %>
...
rest of your terraform HCL code
This prevents the db
stack from ever deploying in the TS_ENV=dev
env. You can also play with count as you noted, those are some options though.