#module-boundary-inputs-outputs
How do you draw a module's boundary? What goes into inputs, what into outputs?
Что отвечать
A module is a black box with a contract. Inputs are whatever changes between uses (the bucket name, the region, tags). Outputs are whatever the outside needs for other resources (an ARN, an endpoint, an id). Inside the module live the locals and the implementation. The antipattern is a module with 40 inputs where half of them mirror fields of an AWS resource. Then the module does not simplify, it adds a layer. A good module hides decisions, it does not pass through every provider option one for one.
Что хотят услышать
A senior should: - name what makes a good input: it changes between calls and has no reasonable default in the module's context - say that an output should return what neighboring resources need, not "everything just in case." Each output is part of the public API, and removing one is a breaking change - separate the three levels: variable (input), local (an internal constant), output (output). A local is not an output, it does not leak out - mention that `description` is required on every variable and output, especially for shared modules. It is documentation, and colleagues read it through `terraform-docs`
Подводные камни
- ✗ Making an input for every attribute of an AWS resource. The module turns into an alias for the resource, with nothing added
- ✗ Giving no defaults to inputs where a reasonable default exists. Every caller writes the same thing
- ✗ Exposing a sensitive value through an output without `sensitive = true`. You leak it into the CI logs by accident
Follow-up
- ? How does `variable` differ from `local` conceptually?
- ? Can you give a default to an `object()` input? What goes inside it?
- ? When should an output be `sensitive = true`?
Глубина в базе знаний