Terraform interview question · Most asked

What are Terraform modules, and how do you design good ones?

Summary

A module is a directory of Terraform configuration with input variables and outputs that can be called repeatedly; every configuration is a root module that may call child modules from local paths, Git, or a registry. Good modules encapsulate one meaningful concept (a VPC, a service, a database), expose a small, well-documented interface, and have sensible defaults.

Longer Answer

Guidelines: avoid thin wrappers around a single resource; avoid "god modules" that do everything with dozens of flags; pin module versions (registry versions or Git tags); validate inputs (validation blocks, types); output the values consumers need; and do not configure providers inside reusable modules (pass them in). Document with examples, and test with terraform test or Terratest.

Organisations often publish internal modules in a private registry so teams self-serve approved patterns (encrypted buckets, tagged resources).

Key Points

  • Reusable units with inputs and outputs.
  • One meaningful concept per module.
  • Pin versions; validate inputs.
  • No provider configuration inside modules.

More most-asked Terraform questions

← All Terraform questions