Hi, I have a problem with renaming resources with ...
# general
g
Hi, I have a problem with renaming resources with aliases. I've read both articles: https://www.pulumi.com/blog/refactoring-iac/ https://www.pulumi.com/docs/intro/concepts/resources/#aliases But I'm not sure how to apply it for my use case and prevent deleting resources After creating several component resources and deploying them I noticed that the parent-child relationship is not correct due to the bug in my code where I merged the
opts
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
Copy code
merged_opts = pulumi.ResourceOptions.merge(
            parent_opts,
            pulumi.ResourceOptions(
                parent=self,
                aliases=[
                    Alias(parent=self),
                    Alias(parent=pulumi.ROOT_STACK_RESOURCE)
                ]
            ),
        )
1