great-sunset-355
07/28/2021, 1:25 PMopts
from parent
into child
- but parent_opts
overridden child_opts
but I wanted it the other way around where I can override parent_opts
with child_opts
during the merge.
For that, I created a sample code: https://gist.github.com/1oglop1/dcb258471cd33f572bedf67c63b7fe00
with 2 merging methods:
- merge_opts_a
- child_opts.merge(parent_opts)
- current & wrong
- merge_opts_b
- ResourceOptions.merge(parent_opts, child_opts)
- expected & correct
When I change from merge_opts_a
to merge_opts_b
and run pulumi preview
it says that I'll delete some resources which I need to prevent.
How can I correctly apply aliases to prevent the deletion of the resources?
Assume all components are supposed to be reusable in another project that does not suffer the current problem.
How is this going to behave when I deploy a different stack with Aliases?
Can the same alias be assigned to multiple components/resources?
Is it possible to pass the alias from the parent without modifying the children's code?
Thank you
Attached pictures: left - current & wrong, right - expected & correct
After trial and error, I managed to solve it by editing the AppComponent
merged_opts = pulumi.ResourceOptions.merge(
parent_opts,
pulumi.ResourceOptions(
parent=self,
aliases=[
Alias(parent=self),
Alias(parent=pulumi.ROOT_STACK_RESOURCE)
]
),
)
No matter how you like to participate in developer communities, Pulumi wants to meet you there. If you want to meet other Pulumi users to share use-cases and best practices, contribute code or documentation, see us at an event, or just tell a story about something cool you did with Pulumi, you are part of our community.
Powered by