Hi. We deployed some resources (AWS VPC, EKS etc) ...
# general
l
Hi. We deployed some resources (AWS VPC, EKS etc) using code in a bunch of classes (eg VPC.py, EKS.py) . Some of those classes have since been converted to ComponentResources. Is there any way to apply the updated classes to the existing stack without breaking stuff? I guess the expected behaviour is the old resources are deleted and replaced with the new ComponentResources. Is there a way to "migrate" to ComponentResources? Thanks
d
You can use the alias resource option for this: https://www.pulumi.com/docs/concepts/options/aliases/
Here's a blog post about refactoring from root-level resources to nested within components: https://www.pulumi.com/blog/cumundi-guest-post/
l
Oh, didn't know about that. Awesome, thank you!
A further question: if I've used the pulumi.ResourceOptions(aliases=['urnpulumistage:aws infraawsxec2Vpc:stage-vpc']) run pulumi up and the resources have been updated , I can then remove the aliases? Thanks
d
Yes
l
Sorry, I'm really having trouble getting the aliases/ResourceOptions right. This is the current stack:
Copy code
pulumi:pulumi:Stack                         aws-infra-stage
  ├─ pulumi:providers:aws                       aws-useast2
  ├─ awsx:ec2:Vpc                           stage-vpc (URN: urn:pulumi:stage::aws-infra::awsx:ec2:Vpc::stage-vpc)
  │     └─ aws:ec2/vpc:Vpc                        stage-vpc

and I want to end up with
pulumi:pulumi:Stack               aws-infra-stage         
 +  ├─ kubetree:platform:VPC             stage           
 +  │    └─ awsx:ec2:Vpc                stage-vpc         
 +  │          └─ aws:ec2:Vpc               stage-vpc
My ComponentResource class looks like:
Copy code
...
class VPC(ComponentResource):
    def __init__(self, name : str,  cidr_block: str, aws_provider: aws.Provider, vpc_id : str=None, opts=None):
        super().__init__('kubetree:platform:VPC', name, {}, opts)
        self.opts = ??
with a method:
Copy code
def create_vpc(self, tags)
    vpcx = awsx.ec2.Vpc(f"{name}-vpc",
                enable_dns_hostnames=True,
                enable_dns_support=True,
                cidr_block=cidr_block,
                subnet_specs=subnet_specs,
                nat_gateways=nat_gateway_conf,
                tags=tags,
                opts=pulumi.ResourceOptions(??)
Update: I used
aliases=[pulumi.Alias(parent=pulumi.ROOT_STACK_RESOURCE),'urn:pulumi:stage::aws-infra::awsx:ec2:Vpc::stage-vpc']
for the opts in the call to
vpcx = awsx.ec2.Vpc()
and it now looks like :
Copy code
pulumi:pulumi:Stack                                                 aws-infra-stage
    │  URN: urn:pulumi:stage::aws-infra::pulumi:pulumi:Stack::aws-infra-stage
    ├─ pulumi:providers:aws                                             aws-useast2
    │     URN: urn:pulumi:stage::aws-infra::pulumi:providers:aws::aws-useast2
    ├─ kubetree:platform:VPC                                            stage
    │     URN: urn:pulumi:stage::aws-infra::kubetree:platform:VPC::stage
    ├─ awsx:ec2:Vpc                                                     stage-vpc
    │  │  URN: urn:pulumi:stage::aws-infra::awsx:ec2:Vpc::stage-vpc
without any of the resources under "urnpulumistage:aws infraawsxec2Vpc:stage-vpc" changing. Yay! Now I just need to reparent "urnpulumistage:aws infraawsxec2Vpc:stage-vpc" to be under "urnpulumistage:aws infrakubetreeplatformVPC:stage" Is that possible? Thanks