https://pulumi.com logo
#general
Title
# general
l

lemon-glass-93199

04/06/2023, 4:54 AM
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;
then
pulumi stack output
returns No output values currently in this stack Provider: Hetzner -
@pulumi/hcloud
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: "10.0.0.0/16" });

//export const networkId = network1.id;
//pulumi.Output.create(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
l

little-cartoon-10569

04/06/2023, 5:00 AM
Have you run
pulumi up
?
And you can use
const
rather than
let
, but I don't think that would break it.
l

lemon-glass-93199

04/06/2023, 5:02 AM
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 😞
l

little-cartoon-10569

04/06/2023, 5:02 AM
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.
l

lemon-glass-93199

04/06/2023, 5:04 AM
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.
l

little-cartoon-10569

04/06/2023, 5:04 AM
Have multiple projects.
l

lemon-glass-93199

04/06/2023, 5:04 AM
Ok, that is probably the problem, I put things in different files, not in index.ts
l

little-cartoon-10569

04/06/2023, 5:05 AM
Other files are other modules. If you export from them, you're exporting from the module, not from the program.
l

lemon-glass-93199

04/06/2023, 5:06 AM
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.
l

little-cartoon-10569

04/06/2023, 5:25 AM
If you're doing different things in different stacks, then you should be using different proejcts.
l

lemon-glass-93199

04/06/2023, 5:26 AM
@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?
l

little-cartoon-10569

04/06/2023, 5:26 AM
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.
l

lemon-glass-93199

04/06/2023, 5:29 AM
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 🙏
l

little-cartoon-10569

04/06/2023, 5:31 AM
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.
l

lemon-glass-93199

04/06/2023, 5:31 AM
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.
16 Views