https://pulumi.com logo
Title
m

magnificent-church-42829

04/22/2022, 5:55 PM
Hi, I am a relatively new user of Pulumi and IaC in general, but iā€™m loving the experience. I have a question about pulumi destroy and the order of steps when deleting resources. I create an internet gateway and map 2 public subnets to it via routetableassociation but when i execute pulumi destroy i get an error about not being able to detach the internet gateway from the VPC because there are still public subnet addresses mapped to it. Here is the error message:
p

polite-napkin-90098

04/22/2022, 7:46 PM
I think the problem with the security groups is that the rules (which refer to the other security groups) would need to be removed before the groups. For the routetableassociations I think if you make it so the DependOn the internet gateway they should be destroyed before it.
m

magnificent-church-42829

04/22/2022, 8:08 PM
@polite-napkin-90098 thank you. So i declare my public subnets first and then when i create my internet gateway i specify in the resourceoptions that it depends on the subnets resources
igw_name = f'{name}-igw'
        self.igw = ec2.InternetGateway(igw_name,
                                       vpc_id=self.vpc.id,
                                       tags={
                                           'Name': igw_name
                                       },
                                       opts=ResourceOptions(parent=self,
                                                            depends_on=self.subnets[:2])
                                       )
i guess that will enforce the order of the destroy steps. It will first remove the subnets then it will be able to detach the gateway from the VPC
p

polite-napkin-90098

04/22/2022, 8:09 PM
Yes, that's my understanding. But I hasten to add I'm fairly new to pulumi myself
šŸ‘ 1
m

magnificent-church-42829

04/22/2022, 8:14 PM
yes, that is correct. From the docs:
The
dependsOn
option ensures that resource creation, update, and deletion operations are done in the correct order.
šŸŽ‰ 1