Open aureq opened 3 years ago
AsIt appears that the change you made to the VPC required replacement of all resources except the InternetGateway, which just needed an update.
Had that succeeded as intended, a new VPC would be created, a new instance would be created in that VPC, the old instance would be deleted, and then the old VPC would be deleted.
Error waiting for internet gateway (igw-0619aca7c131bb260) to detach: timeout while waiting for state to become 'detached' (last state: 'detaching', timeout: 15m0s)
This seems to be the root issue that led to the problems you saw. I'm unsure whether this was a one-off issue, or is consistently reproducible. It sounds like a potential eventual consistency issue in AWS that the upstream AWS provider is not handling. Though it is also not immediately clear that the InternetGateway can successfully update to move between VPCs.
I presume if this repro s consistently, there is likely a smaller repro that triggers this that might make clearer where the issue is.
yes, so that-s an additional point to the discussion. An IGW can either be replaced or recreated. Seems like we are trying to update it (detach/attach) and since there are so many other dependencies related to that resource, then this is what's causing the issue.
@lukehoban Happy to try to find a smaller repro.
It's possible to successfully update a VPC network range if there's no EC2 instance in the said VPC. Many new resources are recreated and at the end the IGW is updated. The IGW id remained the same across updates.
I also tried adding depends_on=[vpc, vpc_igw]
when creating the EC2 instance and then updating the IP range of the VPC but the update failed on the IP range change.
# [...]
ec2 = aws.ec2.Instance(service_name+'-dummy',
instance_type=instance_type,
ami=ami.id,
subnet_id=vpc_subnets[0].id,
vpc_security_group_ids=vpc_public_security_groups,
source_dest_check=False,
user_data_base64=user_data_base64,
iam_instance_profile="",
tags={
'Name': service_name
},
opts=pulumi.ResourceOptions(
parent=vpc_subnets[0],
depends_on=[vpc, vpc_igw]
),
)
It's possible to successfully update a VPC network range if there's no EC2 instance in the said VPC.
Aha - so that's the root of the problem. That's a subtle indirect dependency between those resources which is not manifest in the program or in the Pulumi/Terraform resource models.
You could likely mark your Instance
as delete_before_replace=True
to ensure that it is destroyed before the new instance is created. I expect that would resolve this issue (possibly also requiring the depends_on=[vpc_igw]
).
I tried the delete_before_replace=True
but no luck with that. The stack update is still stuck on updating the IGW (detach/attach) and the EC2 instance is still up and running.
I think it would be simpler to create a new IGW instead of having to detach the existing one when creating the new VPC. Or, have a way to indicate the EC2 instance should be terminated before updating the IGW (Well, likely there are other dependencies in between these 2 resources)
# [...]
ec2 = aws.ec2.Instance(service_name+'-dummy',
instance_type=instance_type,
ami=ami.id,
subnet_id=vpc_subnets[0].id,
vpc_security_group_ids=vpc_public_security_groups,
source_dest_check=False,
user_data_base64=user_data_base64,
iam_instance_profile="",
tags={
'Name': service_name
},
opts=pulumi.ResourceOptions(
parent=vpc_subnets[0],
depends_on=[vpc, vpc_igw],
delete_before_replace=True,
),
)
When updating a VPC IP range that contains an EC2 instance, Pulumi fails to correctly set the stack in the new desired state.
Expected behavior
The VPC and all its resources should be migrated into the new VPC.
Current behavior
The update fails and leaves both stacks (original and new) in an unusable state. 2 EC2 instances are running as well.
Steps to reproduce
In order to reproduce the issue, follow the many steps as described below as described in the 4 phases. Each phase gets its
stack-state-X.json
and I've included the one I generated into the attached stackstates.zipzip
file.pulumi up
: initial deploymentpulumi stack export > stack-state-0.json
Pulumi.dev.yaml
pulumi up
pulumi stack export > stack-state-1.json
pulumi up --refresh
pulumi stack export > stack-state-2.json
pulumi up --refresh
pulumi stack export > stack-state-3.json
pulumi up --refresh
pulumi stack export > stack-state-4.json
Code
Below is
__main__.py
andPulumi.dev.yaml