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.

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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