Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NodeJS/TypeScript programmatic exports #4528

Closed
mrsimonemms opened this issue Apr 30, 2020 · 2 comments
Closed

NodeJS/TypeScript programmatic exports #4528

mrsimonemms opened this issue Apr 30, 2020 · 2 comments
Labels
area/sdks Pulumi language SDKs kind/enhancement Improvements or new features language/javascript

Comments

@mrsimonemms
Copy link

In both Python and Golang, the exports are programmatic - eg, in Python, you call pulumi.export('public_ip', server.public_ip).

For <reasons>, I could do with doing a similar sort of thing in TypeScript - is there any way of getting TS to create outputs with a pulumi method rather than the export const public_ip = server.public_up?

@leezen
Copy link
Contributor

leezen commented Apr 30, 2020

There's no way directly that I know of. Depending on what you're trying to do, an alternative to using the export syntax is to have a top-level function return the outputs as in the second example shown on: https://www.pulumi.com/docs/intro/languages/javascript/#entrypoint

export = async () => {
    // create resources
    return { out: myResource.output };
}

So, you could imagine writing something along the lines of:

export = async () => {
    exports = {};
    const myExport = <T>(key: string, val: pulumi.Output<T>) => {
        exports[key] = val;
    }

    myExport("hello", pulumi.output("test"));

    function foo() {
        myExport("bar", pulumi.output({
            "key": "value"
        }));
    }

    foo();

    // create resources
    return exports;
}

@mikhailshilkov mikhailshilkov added area/sdks Pulumi language SDKs kind/enhancement Improvements or new features language/javascript labels Jun 2, 2022
@mrsimonemms mrsimonemms closed this as not planned Won't fix, can't repro, duplicate, stale Jun 27, 2023
@JElgar
Copy link

JElgar commented Aug 3, 2023

Is it possible to add this to the roadmap? I'm happy to have a look at adding this. The reason being this work around is possible but for some use cases not ideal. My example is I am creating a shared component which creates a container app and a managed certificate in azure. It has a bit of a weird circular dependency so we have to know if the certificate has already been created already or not (and use that to create the definition of the container app). This is managed by creating an output with the certificate id (if its created). Ideally the custom component could create an output in the constructor so the consumer of that component doesn't have to care.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/sdks Pulumi language SDKs kind/enhancement Improvements or new features language/javascript
Projects
None yet
Development

No branches or pull requests

4 participants