Table of Contents
The Error
Error: no matching data source found / Your query returned no results
What Causes This
The data source query returned zero results. The resource doesn’t exist, filters are too restrictive, or you’re in the wrong region.
How to Fix It
Solution 1: Use Wildcards in Filters
data "aws_ami" "ubuntu" {
most_recent = true
filter {
name = "name"
values = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-*"]
}
owners = ["099720109477"]
}
Solution 2: Verify with CLI
aws ec2 describe-images --owners 099720109477 \
--filters "Name=name,Values=ubuntu*jammy*" \
--query 'Images | sort_by(@, &CreationDate) | [-1].ImageId'
Solution 3: Check Region
provider "aws" {
region = "us-east-1" # AMIs are region-specific!
}
Prevention Tips
- Pin provider versions — avoid surprise breaking changes
- Use CI/CD — catch errors before they hit production
- Test with
terraform plan— always review before applying - Keep Terraform updated — newer versions have better error messages
- Use
terraform validate— catches syntax errors early
Hands-On Courses
- Terraform for Beginners on CopyPasteLearn
- Terraform By Example — practical code examples
- Terraform Cheat Sheet — quick reference for all commands
Related Articles
- Terraform Troubleshooting - Common Errors and Solutions
- Terraform Enabling and Using Debugging
- Debugging with TFLint
Conclusion
This error is common and fixable. Follow the solutions above, and check our Terraform course for hands-on training that covers real-world troubleshooting scenarios.

