Hi! I refactored my pulumi code and moved my s3 bu...
# general
f
Hi! I refactored my pulumi code and moved my s3 bucket "results-bucket" resource into a parent resource "results". But now pulumi preview wants to delete the old bucket and create a new one independent of each other. So I thought I need to use an alias but this changed nothing.
Copy code
+   │  ├─ custom:resource:PublicDataBucket                  results                             create      
 +   │  │  ├─ aws:s3:BucketV2                                results-bucket                      create      
 +   │  │  ├─ aws:s3:BucketPolicy                            results-bucket-policy               create      
 -   │  ├─ aws:s3:BucketV2                                   results-bucket                      delete
For the alias I added the following in PublicDataBucket and passed this to awss3BucketV2:
Copy code
self.name = 'results'

super().__init__('custom:resource:PublicDataBucket', name, {}, opts)

child_opts = ResourceOptions.merge(opts, ResourceOptions(parent=self, aliases=[Alias(name='results-bucket')]))

self.bucket = aws.s3.BucketV2(name + '-bucket', opts=child_opts) # this happens in a function which returns the bucket; I simplified it here
I also tried to set the actual URN of the previous results-bucket as alias name but this is also ignored I think. I just need pulumi to recognize that I moved the bucket's definition into a ComponentResource so that it's not recreated. Do you know how I can fix this?
e
You do need an alias but you need to tell it the old parent in the alias, or in this case that it didn't have an old parent.
Copy code
Alias(parent=pulumi.ROOT_STACK_RESOURCE)