AWS limits issue


Launching new instances on AWS can be prevented because of issues like “InstanceLimitExceeded”, “InsufficientInstanceCapacity” etc’.
Is there a way to provide some king of fallback option?
For example, if I get a limit error of “InstanceLimitExceeded” on “t3.large”, try to launch “m5.2xlarge”.

Please advise.

Hey Ido,

Just wanted to make sure you’re aware that those limits can increased. If you create a support ticket and let them know what you need the limit to be the AWS team is usually pretty quick at increasing them for you.

Hi Glenn,

Thank you for follow up.

Yes, I’m aware that I can open a ticket to AWS, but sometimes its necessary to scale up immediately without any actions.

In addition, sometimes the limit can be on AWS side, so ticket won’t help.



Hi @idokaplan,

Terraform doesn’t have any built-in features to automatically select different approaches in response to errors. Terraform’s philosophy is to aim to do what is asked of it or produce an error explaining why not so that a human operator can select an appropriate course of action.

If you have a requirement to dynamically select an instance type based on availability at a particular time then this will require the addition of some system outside of Terraform.

Although Terraform can manage individual EC2 instances directly, in most cases we recommend to use Terraform to create an aws_autoscaling_group and then let AWS autoscaling manage the individual instances. Because autoscaling is a long-running service rather than a one-shot command line tool, it is able to respond automatically to changes in the running infrastructure and, in particular for this use-case, to changes in availability of instances of particular types.

You could use prioritized instance types in a launch template to instruct AWS autoscaling to choose from one of a prioritized list of instance types. By doing this with autoscaling, you also get the benefit of its automatic handling of failed instances, so that a failed instance can potentially be replaced quickly by another instance (possibly of a different type, depending on availability) rather than waiting until the next Terraform run.