What are Terraform data sources?

Answer

Data sources allow Terraform to read information from existing infrastructure or external sources without managing it. Syntax: data "<provider_type>" "<local_name>" { ... }. Example: data "aws_ami" "ubuntu" { most_recent = true; filter { name = "name"; values = ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"] } }. Use its output: resource "aws_instance" "web" { ami = data.aws_ami.ubuntu.id }. Common use cases: look up the latest AMI, read an existing VPC ID to deploy into, get secrets from AWS Secrets Manager, query existing Route53 zones. Data sources query the provider's API during plan — they do not create resources but provide reference data. They are essential for referencing infrastructure managed outside Terraform (manually created or by another team).