int128 / terraform-aws-nat-instance

Terraform module to provision a NAT Instance using an Auto Scaling Group and Spot Instance from $1/month
https://registry.terraform.io/modules/int128/nat-instance/aws/
Apache License 2.0
175 stars 90 forks source link

Fix loop that can run infinitely in some cases #67

Open LiranV opened 12 months ago

LiranV commented 12 months ago

Inside the runonce.sh script there is the aws ec2 attach-network-interface command, If it fails (in my case when the interface was not yet released after system check failure and instance termination) the script goes on and then snat.sh will run.

There the while loop will hand as eth1 will never be available due to the previous failure.

This fix will allow the control flow to continue and reach a user provided script which is given via the user_data variable of this module.

roman8422 commented 10 months ago

Hi @int128 . I ran into this too. Could you merge this PR to fix this please? Thanks.

Edit: actually, it doesn't fix the original problem https://github.com/int128/terraform-aws-nat-instance/issues/57. If interface is not attached for some reason, this change will wait for 3 mins and fail and user will have to handle it using var.user_data_runcmd.

Adding retries in runonce.sh is a better solution imo. Created https://github.com/int128/terraform-aws-nat-instance/pull/72 for this.