kb/resources
Terraform resources and data sources: a resource block describes what to create, a data block describes what to read. Lifecycle options (create_before_destroy, prevent_destroy, ignore_changes), depends_on, count vs for_each are the tools that control how terraform manages the lifecycle of your infrastructure.
count creates N identical resources by index 0..N-1. for_each creates resources keyed from a set or map. Rule of thumb: count for identical copies, for_each when each one has its own settings. When in doubt, use for_each.
data is a block that queries existing infrastructure and returns its attributes to HCL. Terraform creates nothing; it only reads. Use it to reference resources that were not created by Terraform or that live in a different project.
The lifecycle block configures four behaviors: create_before_destroy (zero-downtime replacement), prevent_destroy (deletion guard), ignore_changes (ignore drift on specific attributes), replace_triggered_by (force replacement on an external signal).
A resource block tells Terraform "create this thing in the cloud." It has three parts: the resource type (what it is), the name (how you refer to it internally), and the arguments (how to configure it). Writing these blocks is what you spend 90% of your time doing in Terraform.
Terraform automatically computes the creation order of resources from references in HCL (implicit dependencies). When no such reference exists but order matters, use depends_on. Use it rarely; it is usually a signal that the architecture needs reconsideration.