How to fix terraform error Your query returned no results. Please change your search criteria and try again?

The terraform error Your query returned no results. Please change your search criteria and try again can be misleading and can cause an increase in your debugging time with your Terraform configuration.

I have also faced the same issue while I was trying to set up my aws_instance on AWS.

But interestingly this issue only happened with me when I was trying to create a Data source inside my terraform configuration and I missed adding the depends_on tag inside the data source configuration.

Probably looking at the following screenshot would give you a better idea -

How to fix the error?

  1. First step would be to locate your data source - as you can see in the above diagram you might also be trying to create a data source inside your terraform configuration.
  2. Add depends_on tag - Since I intended to fetch the aws_instance information from the AWS cloud, so I need to add the depends_on tag, otherwise data source configuration would not know what to fetch from AWS.

Here is my correct terraform configuration after fixing the error

 1resource "aws_instance" "ec2_example_with_data_source" {
 3    ami           = "ami-0767046d1677be5a0"
 4    instance_type =  "t2.micro"
 6    tags = {
 7      Name = "Terraform EC2"
 8    }
11data "aws_instance" "myawsinstance" {
12    filter {
13        name = "tag:Name"
14        values = ["Terraform EC2"]
15    }
17    depends_on = [
18      "aws_instance.ec2_example_with_data_source"
19    ]
22output "fetched_info_from_aws" {
23  value = data.aws_instance.myawsinstance.public_ip

Read More -

  1. Install terraform on Ubuntu 20.04, CentOS 8, MacOS, Windows 10, Fedora 33, Red hat 8 and Solaris 11
  2. How to setup Virtual machine on Google Cloud Platform using terraform
  3. Create EC2 Instance on AWS using terraform
  4. How to use Terraform Input Variables
  5. What is and terraform.tfvars?
  6. How to use Terraform locals?
  7. How to use Terraform output values?
  8. Understanding terraform count, for_each and for loop?
  9. Cloud-nuke : How to nuke AWS resources and save additional AWS infrastructure cost?
  10. How to use Terraform Dynamic blocks?
  11. How to use Terraform resource meta arguments?
  12. How to use Terraform Data sources?