6

I'm fairly new to terraform and when creating AWS infrastructure I use the following to fetch the 'available' availability zones for my region (us-east-1) where I'm trying to create an EKS cluster.

data "aws_availability_zones" "available" {}

However when I run a 'terraform apply', it generates the following error because us-east-1a is at capacity.

aws_eks_cluster.demo: error creating EKS Cluster (test-cluster): 
UnsupportedAvailabilityZoneException: Cannot create cluster 'test-cluster' because us-east-1a, the targeted availability zone, does not 
currently have sufficient capacity to support the cluster. Retry and 
choose from these availability zones: us-east-1b, us-east-1c, us-east-1d

Is there any way I can get terraform to handle this automatically or specify that I only want to use 1b,1c,1d etc.

EDIT:

I've realised this is tied with where I create my subnets, which I do using this line:

 availability_zone = "${data.aws_availability_zones.available.names[count.index]}"

So I assume I somehow need to skip us-east-1a by doing something here?

Thanks in advance.

3 Answers 3

1

If anyone else has this issue, here's how I got around it.

Specify a variable with the availability zones you want to target

variable "zones" {
  default = ["us-east-1b", "us-east-1c", "us-east-1d"]
}

When creating your subnets, use this line

availability_zone = "${var.zones[count.index]}"
0

You could use AWS ClI for consult availability zones:

aws ec2 describe-availability-zones

With this result you could prepare a script to take the first result.

0

I know this is an old question but I came across this same issue, and solved it in a different way. Rather than hardcoding the availability zones like the accepted answer, I think it is better to filter out those availability zones that do not support EKS. This approach makes it easier to move to a new region because the data is coming from aws, and not a hardcoded list.

https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/availability_zones#exclude_names

data "aws_availability_zones" "available" {
    # List of availability zones that do not support EKS
    exclude_names = ["us-east-1e"]
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.