quaint-tailor-52411
09/15/2022, 8:50 PMself.register_outputs()
actually do? when I register some child resources there and then later try to access them as a property of component object i get object no attribute my_outputted_resource
stocky-restaurant-98004
09/15/2022, 8:53 PMquaint-tailor-52411
09/15/2022, 8:54 PM# We also need to register all the expected outputs for this component resource that will get returned by default.
self.register_outputs({
"virtual_network": virtual_network,
"subnet": subnet,
})
Traceback (most recent call last):
File "/Users/james/repos/cyclecloud/vm/./__main__.py", line 96, in <module>
virtual_network_components[f"{SERVICE}-{location}"] = virtual_network.VirtualNetworkComponent(
File "/Users/james/repos/cyclecloud/vm/./virtual_network.py", line 28, in __init__
first_address_prefix = self.virtual_network.address_space.address_prefixes[0]
AttributeError: 'VirtualNetworkComponent' object has no attribute 'virtual_network'
stocky-restaurant-98004
09/15/2022, 8:55 PMyour_component.virtual_network
is not defined?self
is a little confusing to me, but I am probably missing somethingquaint-tailor-52411
09/15/2022, 8:57 PMregister_outputs
was not workingimport pulumi
from pulumi_azure_native import network
class MyComponent(pulumi.ComponentResource):
def __init__(self, name, props=None, opts=None):
super().__init__("pkg:network:MyComponent", name=name, props=None, opts=opts)
child_opts = pulumi.ResourceOptions(parent=self)
virtual_network = network.VirtualNetwork(
"name",
address_space=network.AddressSpaceArgs(
address_prefixes=[
"10.0.0.0/8",
],
),
location="westus",
resource_group_name="myRG",
virtual_network_name="vnetName",
opts=pulumi.ResourceOptions(
parent=self,
),
)
self.register_outputs({
"virtual_network": virtual_network,
})
import component
mycomponent = component.MyComponent("mycomponent")
mycomponent.virtual_network
error: Program failed with an unhandled exception:
Traceback (most recent call last):
File "/Users/james/repos/cyclecloud/vm/./__main__.py", line 22, in <module>
mycomponent.virtual_network
AttributeError: 'MyComponent' object has no attribute 'virtual_network'
stocky-restaurant-98004
09/15/2022, 9:09 PMquaint-tailor-52411
09/15/2022, 9:15 PM(.venv) jamess-MacBook-Pro:vm james$ pulumi version
v3.39.3
stocky-restaurant-98004
09/15/2022, 9:16 PMquaint-tailor-52411
09/15/2022, 9:18 PMstocky-restaurant-98004
09/15/2022, 9:22 PMself.virtual_network = ...
, and you do not need to call register_outputs
. I'll submit a PR to update the docs, and my apologies for hitting this. Our docs should be clearer on this subject.quaint-tailor-52411
09/15/2022, 9:30 PMchild_opts = pulumi.ResourceOptions(parent=self)
stocky-restaurant-98004
09/15/2022, 9:41 PMparent=self
for each resource in the component because that's how you inherit the provider.quaint-tailor-52411
09/15/2022, 9:44 PM