From cd427c13503a5847faae141406685497c60c3d23 Mon Sep 17 00:00:00 2001 From: Mathias Lykkegaard Lorenzen Date: Mon, 25 Sep 2023 12:31:56 +0200 Subject: [PATCH] feat: add helper for strong-typed stack references --- .../src/generators/init/files/index.ts.template | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/packages/pulumi/src/generators/init/files/index.ts.template b/packages/pulumi/src/generators/init/files/index.ts.template index 5d0da025..5fa794ab 100644 --- a/packages/pulumi/src/generators/init/files/index.ts.template +++ b/packages/pulumi/src/generators/init/files/index.ts.template @@ -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 = ExportTypes[TKey]; + +type StrongTypedStackReference = Omit & { + getOutput(name: pulumi.Input): ExportTypesValue; + requireOutput(name: pulumi.Input): ExportTypesValue; +}; + +export function getStackReference() { + const stack = pulumi.getStack(); + return new pulumi.StackReference(`organization/<%= name %>/${stack}`) as StrongTypedStackReference; +}