Error: Your query returned no results. Please change your search criteria and try again.

Today I’m trying to use terraform to build a eks cluster. I was following the official terraform AWS EKS Introduction documentation.

I got everything setup required from the documentation. But I was getting the following error when running the terraform apply.

 
Error: Your query returned no results. Please change your search criteria and try again.

After the investigation, I found the original documentation was try to search the AMI images from your own account, which means if you dont have an AMI stores in your account. nothing would be found.

The file that terraform provide:

data "aws_ami" "eks-worker" {
  filter {
    name = "name"
    values = ["amazon-eks-node-${aws_eks_cluster.demo.version}-v*"]
    # values = ["amazon-eks-node-v*"]
  }

  most_recent = true
  owners = ["9999999"] # Amazon EKS AMI Account ID
}

Since I dont have and dont want to keep AMI within my account. and this is just a demo cluster. So I changed the filter to find the AMI from Amazon as follow:

data "aws_ami" "eks-worker" {
  filter {
    name = "name"
    values = ["amazon-eks-node-${aws_eks_cluster.demo.version}-v*"]
    # values = ["amazon-eks-node-v*"]
  }

  most_recent = true
  owners = ["amazon"] # Amazon EKS AMI Account ID
}

And this works. Account way to check is to use the describe-images awscli. I use the following a lot just for test whether I can find the AMI that I want.

aws ec2 describe-images --filters "Name=name,Values=amazon-eks-node-v*" --owner amazon --region us-east-2