Module 5: Reconnaissance
Sometimes you don't want to build a new resource; you just want to find information about an existing one. For this, we use Data Sources.
Tactical Intel: Data Blocks
A resource block says: "Build this."
A data block says: "Find this."
Why use Data Sources?
Imagine you need to launch a server, but you need to know which subnet is available. You use a data source to ask AWS: "Give me the ID of the public subnet."
Step 1: The Query
We're going to ask Terraform to find the information about the bucket we created earlier.
Mission: Add a data block to your main.tf:
data "aws_s3_bucket" "existing_intel" {
bucket = "terraform-mission-bucket"
}
booting...
Tactical Insight: Read-Only
Data sources are strictly Read-Only. Terraform will never modify or delete anything referenced in a data block. It is purely for gathering intelligence.