Terraform

Is there such a thing as combining data sources? What would be the use case?

Difficulty: unrated

Source: bregman-arie/devops-exercises by Arie Bregman

Answer

Yes, you can define a data source while using another data source as a filter for example.

Let's say we want to get AWS subnets but only from our default VPC:

data "aws_subnets" "default" {
  filter {
    name   = "vpc-id"
    values = [data.aws_vpc.default.id]
  }
}