Hi everyone. I'm trying to export and output from ...
# general
Hi everyone. I'm trying to export and output from one stack, to be used in another stack from the same project, but have been unable to do it. Summary:
export let network1Exp = network1.id;
pulumi stack output
returns No output values currently in this stack Provider: Hetzner -
I have made sure I'm running the stack output command in the correct stack. More info in thread ----> Any help appreciated 🙏
Code with some things I have tried:
Copy code
import * as pulumi from "@pulumi/pulumi";
import * as hcloud from "@pulumi/hcloud";

const network1 = new hcloud.Network("network", { ipRange: "" });

//export const networkId = network1.id;
//export let network1Exp = network1;
export let network1Exp = network1.id;
Copy code
pulumi stack output --stack org/proj/networks 
Current stack outputs (0): 
   No output values currently in this stack
Have you run
pulumi up
And you can use
rather than
, but I don't think that would break it.
Yes I ran pulumi up for that stack and tried exporting using those methods that are commented out, each time destroying and recreating the stack. But no luck so far 😞
Aside: it is very rarely that you should be importing values into a stack in the same project. Generally that is a sign of a design mistake.
Is this code in index.ts? Exporting from other modules doesn't do what you want.
I see, I'm doing it like that because I tried putting everything in the same stack but wasn't working because for example, to create the subnet i had to create first the network. This was messing up previews and I wanted to have everything looking nice and being able to do previews.
Have multiple projects.
Ok, that is probably the problem, I put things in different files, not in index.ts
Other files are other modules. If you export from them, you're exporting from the module, not from the program.
Thank you! I got more to experiment with what you said, was stuck in a loop until now.
Will try that, to use different projects. Or maybe separate the stacks in same project but export from index.ts to see what happens.
If you're doing different things in different stacks, then you should be using different proejcts.
@little-cartoon-10569 I was able to do it thanks to your advise. And even using multiple stacks in a single project. I'm handling each stack like this
if (stack === "networks")
can I tip you with btc? maybe you have a lightning wallet?
No tip required, thanks 🙂
It's generally better to prefer multiple projects, than one do-everything project with different code per stack.
Doing it that way makes it difficult to have different target envrionemnts. If you have a stack "network", is that the dev or prod "network"? The Europe or US "network"?
You'll end up re-implementing the intended use of stacks via if-statements.
Ok thanks for the advise, the reason I'm wanting to do multi stack in one project. It's because its really a single project, but for previews to work, I need to first deploy some stuff so that the IDs are ready and the other stack can read them. And I wanted to use the same folder for this project. But I understand your point, I'm a beginner in this and might switch to what you say later 🙏
You shouldn't need to deploy something first for the other stack. That's what Pulumi is for. If you need the id from one resource in another resource, then you just pass it in. You don't need to wait for it to be deployed.
Okok I will try again later, it might have been something else I was doing wrong. I did too many changes today and my brain is a bit toast.