This message was deleted.
# general
s
This message was deleted.
b
Are Stack A, B and C from the same Pulumi project?
g
good question, I should've clarified that - they're each in separate projects. we're using a module approach within the organisation. I'll update the post!
b
So in stack A, wouldn’t you just export an output, then reference it in Stack B and Stack C as a stack reference?
which language SDK are you using?
g
using Python. the thinking was I didn't want to repeat the same code writing the
StackReference
in multiple places to get the same
Output
so my logic was to create a function in the module where it came from, to be reused in multiple places elsewhere
b
Generally that’s a 1 line code, but I will often abstract that away into a class, something like this:
Copy code
class VpcStackInfo(pulumi.StackReference):
    vpc_id = pulumi.Output[Any]
    private_subnet_ids = pulumi.Output[Any]
    public_subnet_ids = pulumi.Output[Any]
    cidr_block = pulumi.Output[Any]

    def __init__(self, stack_name: str):
        super().__init__(f"ignistech/vpc/{stack_name}")

        self.vpc_id = self.require_output("vpc_id")  # type: ignore
        self.private_subnet_ids = self.require_output("private_subnet_ids")  # type: ignore
        self.public_subnet_ids = self.require_output("public_subnet_ids")  # type: ignore
        self.cidr_block = self.require_output("cidr_block")  # type: ignore
Then reference it like this:
Copy code
vpc = stackinfo.VpcStackInfo(STACK)
I really try not to use cross referenced functions, you run into lots of issues that way
g
thanks for your help and suggestions I'll give that a go!
I've used the class approach and I think it's better, thanks! the
preview
is still failing for
B
because
A
hasn't been
up
'd yet I think. But all the changes are going together in the pipeline. Is there something I'm missing for dependency on
A
by
B
that needs to be declared for the
preview
to work?