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

  1. Pin provider versions — avoid surprise breaking changes
  2. Use CI/CD — catch errors before they hit production
  3. Test with terraform plan — always review before applying
  4. Keep Terraform updated — newer versions have better error messages
  5. Use terraform validate — catches syntax errors early

Hands-On Courses

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.