Day 13 was an important milestone in my Terraform learning journey. Until now, most of my work was about creating and managing resources. Today, I learned something equally powerful — data sources.
Data sources allow Terraform to read existing infrastructure instead of creating new resources. This concept made Terraform feel more practical and closer to real-world use cases.
What Are Data Sources in Terraform?
A data source is used when:
- A resource already exists in AWS
- You want to reference it in Terraform
- You don’t want Terraform to create or modify it
In simple words, resources create, but data sources read.
Why Data Sources Are Important
In real projects, not everything is created by Terraform. Sometimes:
- VPCs already exist
- AMIs are prebuilt
- IAM roles are managed by another team
- S3 buckets already exist Data sources help Terraform fetch this information and use it safely.
Basic Syntax of a Data Source
data "<provider>_<resource_type>" "<name>" {
# filters or identifiers
}
Common AWS Data Sources I Explored
- VPC
- Subnet
- AMI
Resource vs Data Source (Simple Understanding)
- Resources create and manage
- Data sources read and reference
- Resources change infrastructure
- Data sources do not make changes
Understanding this difference cleared up a lot of confusion for me.
What I Took Away from Day 13
- Data sources make Terraform more dynamic
- Existing infrastructure can be reused safely
- Hardcoding values should be avoided
- Most real-world Terraform projects rely heavily on data sources
Top comments (0)