Skip to content

Commit

Permalink
feat: add helper for strong-typed stack references
Browse files Browse the repository at this point in the history
  • Loading branch information
ffMathy authored Sep 25, 2023
1 parent fc493e1 commit cd427c1
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions packages/pulumi/src/generators/init/files/index.ts.template
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,19 @@ register({

import './pulumi'
export * from './pulumi'

import * as pulumi from '@pulumi/pulumi';

type ExportTypes = typeof import('./pulumi');
type ExportTypesKey = keyof ExportTypes;
type ExportTypesValue<TKey extends ExportTypesKey> = ExportTypes[TKey];

type StrongTypedStackReference = Omit<pulumi.StackReference, 'getOutput' | 'requireOutput'> & {
getOutput<T extends ExportTypesKey>(name: pulumi.Input<T>): ExportTypesValue<T>;
requireOutput<T extends ExportTypesKey>(name: pulumi.Input<T>): ExportTypesValue<T>;
};

export function getStackReference() {
const stack = pulumi.getStack();
return new pulumi.StackReference(`organization/<%= name %>/${stack}`) as StrongTypedStackReference;
}

0 comments on commit cd427c1

Please sign in to comment.