Skip to content

Commit

Permalink
feat: add env to pulumi function args list
Browse files Browse the repository at this point in the history
  • Loading branch information
adrians5j committed Jun 17, 2024
1 parent 20d45ed commit 97fed18
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/pulumi/src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const DEFAULT_PROD_ENV_NAMES = ["prod", "production"];
15 changes: 15 additions & 0 deletions packages/pulumi/src/createPulumiApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
} from "~/types";
import { PulumiAppRemoteResource } from "~/PulumiAppRemoteResource";
import cloneDeep from "lodash/cloneDeep";
import { DEFAULT_PROD_ENV_NAMES } from "./constants";

export function createPulumiApp<TResources extends Record<string, unknown>>(
params: CreatePulumiAppParams<TResources>
Expand Down Expand Up @@ -64,13 +65,27 @@ export function createPulumiApp<TResources extends Record<string, unknown>>(
create: params.config || {},
run: {}
},
env: {
name: "",
isProduction: false
},
decorateProgram: cb => {
programDecorators.push(cb);
},

async run(config) {
app.params.run = config;

// Add environment-related variables.
const productionEnvironments =
app.params.create.productionEnvironments || DEFAULT_PROD_ENV_NAMES;
const isProduction = productionEnvironments.includes(app.params.run.env);

app.env = {
name: app.params.run.env,
isProduction
};

const programOutput = programDecorators.reduce<PulumiProgram<PulumiApp<TResources>>>(
(program, decorator) => {
return app => decorator(program, app);
Expand Down
15 changes: 15 additions & 0 deletions packages/pulumi/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface CreatePulumiAppParams<TResources extends Record<string, unknown
name: string;
path: string;
config?: CreateConfig;

program(app: PulumiApp): TResources | Promise<TResources>;
}

Expand All @@ -49,6 +50,16 @@ export interface PulumiApp<TResources = Record<string, unknown>> {
create: CreateConfig;
run: RunConfig;
};
env: {
name: string;

// Set to `true` if the environment into which the application is being deployed
// is considered a production environment. The list of environment names
// that are considered production environments is defined via the
// `productionEnvironments` parameter. Learn more:
// https://www.webiny.com/docs/infrastructure/basics/modify-cloud-infrastructure#defining-multiple-production-environments
isProduction: boolean;
};

run(params: RunConfig): Record<string, any>;

Expand All @@ -62,19 +73,23 @@ export interface PulumiApp<TResources = Record<string, unknown>> {
addRemoteResource<T>(name: string, getter: () => Promise<T>): PulumiAppRemoteResource<T>;

addOutput<T>(name: string, output: T): void;

addOutputs(outputs: Record<string, unknown>): void;

addModule<TModule>(def: PulumiAppModuleDefinition<TModule, void>): TModule;

addModule<TModule, TConfig>(
def: PulumiAppModuleDefinition<TModule, TConfig>,
config: TConfig
): TModule;

getModule<TConfig, TModule>(def: PulumiAppModuleDefinition<TModule, TConfig>): TModule;

getModule<TConfig, TModule>(
def: PulumiAppModuleDefinition<TModule, TConfig>,
opts: { optional: false }
): TModule;

getModule<TConfig, TModule>(
def: PulumiAppModuleDefinition<TModule, TConfig>,
opts: { optional: true }
Expand Down

0 comments on commit 97fed18

Please sign in to comment.