TECHNOLOGIESTieInn Technologies

Modules you can reuse

Terraform · 12 questions

Short notes

Key idea

A module is a folder of Terraform files used like a function: inputs (variables) in, resources built, outputs out. Modules stop you copying the same blocks for every team or environment.

Syntax

module "sales_lake" {
  source     = "./modules/lake"
  name       = "sales"
  location   = "asia-south1"
  keep_days  = 365
}
output "raw_bucket" { value = module.sales_lake.raw_bucket_name }
  • The module folder has variables.tf, main.tf, outputs.tf.
  • Sources: local paths, Git URLs (?ref=v1.2.0), the Terraform Registry (with version).
  • terraform init after adding or changing a module source.

Example

A lake module creates a raw bucket, a curated bucket, a dataset and the IAM for one domain. Calling it three times (sales, marketing, finance) builds three identical lakes from 15 lines.

Traps

  • Pin module versions; an unpinned Git source can change under you.
  • Too many tiny modules make code hard to follow; modularise repeated groups, not single resources.
  • Moving resources into a module changes their addresses; use moved blocks to avoid recreating them.
  • Expose only the outputs callers need.

Want the full lesson with step-by-step examples, a project and a certificate? Terraform course, ₹120 →

Questions

Open in Code Lab5 free questions
5 questions

    Modules you can reuse

  1. Question 1easy

    What is a Terraform module?

  2. Modules you can reuse

  3. Question 2medium

    Which blocks become a module's inputs?

  4. Modules you can reuse

  5. Question 3easy

    In a module block, what does source do?

  6. Modules you can reuse

  7. Question 4medium

    You add a new module block and run terraform plan. It fails with "Module not installed". What do you run?

  8. Modules you can reuse

  9. Question 5hard

    You need the bucket's URL from inside a module, but the module has no output for it. What's right?

7 more questions on this topic, with hints, and tests

Sign up free for 21 days of every question and test.