how/modules
What happens at the root → child module boundary: input through variable, output through output, and why a module stays reusable only if it does not reach for global providers.
A module in Terraform is a function. It has parameters
(variable), it has a body (resource), it has a return value
(output). The root config calls the module through a module "..."
block. That is the "function call."
Press ▶ to see how one and the same S3 bucket can be described with a reusable module, and what Terraform does at each step.
main.tf has a module "bucket" block. source says where to
get the module code: a local folder, git, the Terraform Registry.
The module itself (modules/bucket/) sits next to it, but is not
activated yet. Terraform only discovered it during init. At this
stage the module is just downloaded files, no resources are created.
recap
What matters to remember:
variable. No global state, no "magic" providers, only what you
declared explicitly. That is what makes a module reusable.sensitive = true on a variable or output is preserved when it
crosses the boundary. Terraform masks the value in logs and in the
plan. See tf-sensitive.providers = { aws = aws.us-east-1 }. Otherwise the module uses
root's default provider, and multi-region scenarios break.Next: tf-remote-backend-lock on how two engineers work with the same state at the same time.