data source
What is data source?
data source: Reads existing information from a provider without creating anything — look up an AMI, an existing VPC, your account ID. A data source in Terraform reads information that already exists, without creating or changing anything. You can look up the latest Ubuntu image, an existing network, a DNS zone or your account ID.
Frequently asked questions about data source
How is data source used in practice?
It lets your configuration work with resources managed elsewhere, by another team, another Terraform project or by hand. Instead of copying an ID into your code, you look it up by name each time.
What should you keep in mind with data source?
Data sources are read during every plan, so they always reflect the current state. That is usually what you want, but it can surprise you. A lookup for "the most recent image" may return a new one next week, and Terraform will then propose replacing your servers. Pin to a specific version when stability matters more than freshness.
What does an example of data source look like?
data "aws_ami" "ubuntu" { most_recent = true owners = ["099720109477"] } At a glance
| Category | Terraform |
|---|---|
| Explained by | Reinier de la Parra |
| Updated |