Variable validation
Reject invalid caller input before provider work begins.
Chapter 6 of 24
Small inputs and explicit outputs make infrastructure composition reviewable.
Reject invalid caller input before provider work begins.
Guard assumptions before an action or a resulting attribute after it.
Report a continuous health expectation without changing ownership.
Publish only values a caller needs, not a provider-object dump.
Keep a module around a coherent lifecycle and contract. A module that forwards every argument to one resource adds a second place to debug with no new boundary.
A VPC, an EKS cluster, and application data have different blast radii. Give each a small input contract and expose stable IDs or ARNs. Put IAM policy and account assumptions at the caller boundary where reviewers can see them.
Open labs/06-modules/main.tf and the typed module input. One object carries related application and environment values.
cd learn-terraform/labs/06-modules
terraform init -backend=false
terraform validate
terraform plan
tofu init -backend=false
tofu validate
tofu planThe module emits course-learning. Change the environment to any other value to see validation fail before an AWS provider is involved.
| Review | Expected |
|---|---|
| Input shape | Every field has a type, description, and domain check where needed. |
| Output | A stable caller-facing value, not an entire provider object. |
| Size | One lifecycle boundary, not a resource wrapper. |
any hides a contract breach until a provider plan is harder to read.name_prefix is course-learning.This lab has no provider resources. Remove only a generated .terraform directory; do not commit it.
When the rule depends on a planned resource or another input rather than one variable.
No. Extract only a reusable lifecycle and contract.
Module quality comes from a clear boundary, not from the number of files. Next, select environment inputs and exercise them with native tests.