select
View SourceMulti-stack deployment pattern that allows a single Pulumi project to deploy different types of stacks based on configuration. This is essential for separating stateful infrastructure from stateless applications while maintaining shared code.
import * as saws from "@stackattack/aws";
function env() { const ctx = saws.context();
const certificate = saws.certificate(ctx, { domain: "mydomain.dev", wildcard: true });
return { certificate };}
function app() { const ctx = saws.context(); const config = new pulumi.Config();
const envStack = saws.stackRef(config.require('env-stack'), env); const certificate = envStack.require('certificate');
const bucket = saws.bucket(ctx, { paths: ["./dist"] });
const site = saws.staticSite(ctx, { domain: "docs.mydomain.dev", certificate, bucket, adapter: saws.astroAdapter() });
return { url: site.url };}
export default () => saws.select({ env, app });
Configure stack types using Pulumi config:
# Create environment stackpulumi stack init my-env-stackpulumi config set stack-type envpulumi up
# Create app stackpulumi stack init my-app-stackpulumi config set stack-type apppulumi config set env-stack my-env-stackpulumi up
This pattern enables you to deploy shared infrastructure separately from applications, allowing for faster deployments and better isolation. See the Structuring Stacks guide for recommendations on separating your resources into stacks.
Functions
Section titled “Functions”select
Section titled “select”Selects and executes a function based on the ‘stack-type’ configuration value.
function select(funcs: Record<string, () => unknown>): unknown
Parameters
Section titled “Parameters”funcs
(Record<string, () => unknown>
) - Record of function names to functions that can be executed
Returns
Section titled “Returns”- (
unknown
) - Selects and executes a function based on the ‘stack-type’ configuration value.