Data sources in Terraform allow you to retrieve information about existing resources outside of the current Terraform configuration. Data sources are read-only and do not create or modify resources
Common use cases for data sources include:
terraform import
commandThe arguments can vary depending on the data source
// existing vpc
variable "vpc_id" {}
data "aws_vpc" "selected" {
id = var.vpc_id
}
resource "aws_subnet" "example" {
vpc_id = data.aws_vpc.selected.id
availability_zone = "us-west-2a"
cidr_block = cidrsubnet(data.aws_vpc.selected.cidr_block, 4, 1)
}