RaJiska / terraform-aws-fck-nat

Terraform module for fck-nat
https://registry.terraform.io/modules/RaJiska/fck-nat/aws/latest
MIT License
74 stars 39 forks source link

Support for multiple subnet IDs #38

Open fermanjj opened 2 months ago

fermanjj commented 2 months ago

Currently it appears the module supports only a single subnet ID. This means if you're using spot instances in an ASG, you can get denied provisioning an instance due to limited capacity in that specific Availability zone you've allocated the subnet to.

The exact error for more context:

We currently do not have sufficient t4g.nano capacity in the Availability Zone you requested (us-east-1a). Our system will be working on provisioning additional capacity. You can currently get t4g.nano capacity by not specifying an Availability Zone in your request or choosing us-east-1b, us-east-1c, us-east-1d, us-east-1f. Launching EC2 instance failed.

I don't see a good way to address this at the moment since the whole thing relies on a single network interface/subnet.

RaJiska commented 2 months ago

Just as for AWS' NAT Gateway service, this module only spans across one availability zone. You might want to use multiple instance types within your ASG to mitigate the issue of instance shortage when using spot instances

callumthomson commented 1 month ago

@RaJiska

Just as for AWS' NAT Gateway service, this module only spans across one availability zone.

I would agree, but this is a problem unique to spot instances, which does not apply to NAT gateways and I think this module can solve it easily.

While launching an EC2 instance requires a subnet, In HA mode specifically, the ASG can and should be created to include multiple subnets. I had this error today on my fck-nat instance that was already running and was interupted:

Launching a new EC2 instance. Status Reason: We currently do not have sufficient t4g.nano capacity in the Availability Zone you requested (eu-west-2a). Our system will be working on provisioning additional capacity. You can currently get t4g.nano capacity by not specifying an Availability Zone in your request or choosing eu-west-2b, eu-west-2c. Launching EC2 instance failed.

Because of the way this module creates the ASG, it was not able to replace the instance in another subnet.

You might want to use multiple instance types within your ASG to mitigate the issue of instance shortage when using spot instances

It doesn't seem like there is an option to specify more than 1 instance type for the ASG in this module. The only other option that I can think of would be to create multiple instances of this module with a different instance type/subnet id, therefore creating multiple NAT instances. This means higher cost.

I think multiple subnets should be an option when using an ASG (HA mode). If you want to limit to a single subnet, then you should also have that option.