Terraform Data Sources Explained
Learn how Terraform data sources read existing infrastructure, lookup cloud resources, and connect reusable Terraform code with real environments.
Quick answer
Resource
Creates or manages infrastructure.
Data source
Reads existing information from a provider.
What is a Terraform data source?
A data source lets Terraform read information about existing resources without managing their full lifecycle.
Example
data "aws_ami" "ubuntu" { most_recent = true owners = ["099720109477"] filter { name = "name" values = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"] } }
Using the data source
resource "aws_instance" "web" { ami = data.aws_ami.ubuntu.id instance_type = "t3.micro" }
Common use cases
- Find latest AMI/image.
- Read existing VPC/subnet.
- Lookup DNS zone.
- Read existing key vault or secret reference.
- Fetch Kubernetes cluster information.
Common mistakes
- Using data sources when Terraform should manage the resource.
- Using broad filters that match the wrong resource.
- Not understanding that data sources are read during plan/apply.
Best practices
- Use precise filters.
- Name data sources clearly.
- Document externally managed resources.
- Avoid relying on unstable lookup results for production.
Related guides
- Terraform Learning Path
- Terraform Providers Explained
Official references
- Terraform data sources documentation
Join the discussion
0 CommentsAsk questions, add context, or share what worked.
More from Melochip Editorial
Learn what Playwright testing is, why modern QA teams use it, how testers can get started, and the major types...
7 min read · Sep 19, 2026
Learn how Kubernetes Deployments and ReplicaSets work with practical YAML, scaling, self-healing, rolling upda...
7 min read · Sep 17, 2026
Learn Kubernetes security best practices with RBAC, Secrets, ServiceAccounts, Pod securityContext, NetworkPoli...
6 min read · Sep 17, 2026Related articles
Learn how Kubernetes Deployments and ReplicaSets work with practical YAML, scaling, self-healing, rolling upda...
7 min read · Sep 17, 2026
Learn Kubernetes monitoring and logs with kubectl logs, events, metrics-server, top commands, Prometheus, Graf...
5 min read · Sep 17, 2026
Learn Kubernetes Ingress with controllers, IngressClass, host and path routing, TLS, DNS, annotations, redirec...
8 min read · Sep 17, 2026
Learn Kubernetes ConfigMaps and Secrets with YAML, environment variables, file mounts, update behavior, immuta...
8 min read · Sep 17, 2026Stay in the loop. Get new Melochip articles
Receive Melochip article updates when new articles are available. Explicit opt-in only.
No comments yet. Start the discussion.