great-sunset-355
07/22/2021, 11:08 AMregister_outputs
vs pulumi.export()
that provides stack outputs.
I have 2 projects
core
and app
inside core
there is a ComponentResource
class MyTopic(ComponentResource):
"""My SNS Topic"""
def __init__(self, config: TopicModel, opts: ResourceOptions = None):
super().__init__(
"stekz:components:aws:sns-topic",
config.name,
None,
opts,
)
self.topic = sns.Topic(
"component_topic",
name_prefix=config.name_prefix,
)
self.register_outputs(
{
'component_topic_name': self.topic.name,
}
)
# now we instantiate the resource
MyTopic(
config=TopicModel(
name='core-imported',
name_prefix='cp'
)
)
By doing so I expected to be able to refer to MyTopic.outputs.component_topic_name
from app
however that does not seem to be possible because all I can do is to use the StackReference
. But stack reference can only refer to outputs from pulumi.export('key', 'value)
So instead of using register_outputs
I'd have to do this:
t= MyTopic(
config=TopicModel(
name='core-imported',
name_prefix='cp'
)
)
pulumi.export('component_topic_name', t.name)
Which I consider quite ineffective in case this has to be done on a larger amount of resources. Of course, I can wrap it in the function and invent my own convention for this but my point is that I should not have to.
I see this as a problem inherited from terraform which suffers a very similar problem. https://github.com/hashicorp/terraform/issues/8554
I wonder if these issues is somehow related to my problem: https://github.com/pulumi/pulumi/issues/2653, https://github.com/pulumi/pulumi/issues/5941
thank you.
I'm curious if there is any specific limitation that does not allow referencing to the outputs of another stack the way I'd expect or is just the result of the initial implementation where pulumi team took ideas from existing solutions?
Thank youbillowy-army-68599
07/22/2021, 5:15 PMclass MyTopic(ComponentResource):
component_topic_name: pulumi.Output[str]
self.component_topic_name = self.topic.name
self.register_outputs(
{
'component_topic_name': self.topic.name,
}
)
It should workgreat-sunset-355
07/23/2021, 8:30 AMclass attribute
just to get the output. (I'd suggest using a data class for config instead of a regular class)
I may have misunderstood the purpose of register_outputs
.
It updates resource outputs.
I expected the function to update stack outputs updated as well when I instantiate the resource.
Here is a gist with the code and expected output:
https://gist.github.com/1oglop1/fb87b89636aebaeb5945863dbeca4ec3