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 -

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



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" {
 2
 3    ami           = "ami-0767046d1677be5a0"
 4    instance_type =  "t2.micro"
 5
 6    tags = {
 7      Name = "Terraform EC2"
 8    }
 9}
10
11data "aws_instance" "myawsinstance" {
12    filter {
13        name = "tag:Name"
14        values = ["Terraform EC2"]
15    }
16
17    depends_on = [
18      "aws_instance.ec2_example_with_data_source"
19    ]
20}
21
22output "fetched_info_from_aws" {
23  value = data.aws_instance.myawsinstance.public_ip
24}



Read More - Terragrunt -

  1. How to use Terragrunt?

Posts in this Series