Data Sources

  • Data sources allow Terraform to use information defined outside of Terraform, defined by another separate Terraform configuration, or modified by functions.
  • Data sources are like resources, but they don't create anything, just get some data you can refer to.
  • A data source is accessed via a special kind of resource known as a data resource, declared using a data block:
1data "aws_ami" "example" {
2  most_recent = true
3
4  owners = ["self"]
5  tags = {
6    Name   = "app-server"
7    Tested = "true"
8  }
9}
  • This data source get aws amis that are owned by the user, and have these appropriate names.
  • This is how you would refer them later:
1data.aws_ami.example.id

(see more details about aws_ami data source)

Read more about data sources in the Terraform documentation