Terraform modules interview questions: source, versioning and reuse

Reviewed by Mark Dickie · Last updated

8 questions on this page you can answer and see marked on the spot. Go to the first one

Terraform modules are reusable directories of .tf files that wrap resources behind input variables and outputs. Interviewers usually test how a calling configuration passes values into a module, how it pins the module's source and version, and where state lives. Expect to explain the difference between the root module and the child modules it calls, and why child modules have no state file of their own.

Which module block arguments come up in interviews?

ArgumentWhat it controlsCommon mistake
sourceWhere Terraform fetches the module: a local path, a registry address, or a Git URLLocal paths need no download, but registry and Git sources need terraform init first
versionA constraint such as "~> 5.0" on registry modulesVersion is not valid on local paths, and Git sources pin with ref= in the URL instead
count or for_eachCreates several instances of one module blockInstances get addresses like module.vpc["prod"], so renaming a key plans a destroy and create
providersPasses provider configurations into the moduleA child module using aliased providers needs an explicit providers map
depends_onOrders a module instance after other resourcesIt orders the whole module, which can widen the plan and slow applies

How do you version and publish a Terraform module?

  1. Tag a release in the module's Git repository with a semantic version such as v2.3.0.
  2. Publish the repository to the public or a private Terraform registry, which reads those tags as available versions.
  3. In the calling configuration, set version = "~> 2.3" so patch and minor releases are accepted while a major bump is blocked.
  4. Run terraform init -upgrade to fetch the newest release the constraint allows.
  5. Read the plan before applying, because a changed default value in the module can replace resources on upgrade.

Work through the questions below in order, since the later ones assume you can explain these two areas.

Key facts

  • Tarmac has 25 Terraform interview questions on this topic, 10 of them on this page, at difficulty 1–4 of 5.
  • Tarmac tracked 963 job postings asking for Terraform in November 2026.
  • Roles asking for Terraform advertise a median base salary of £77,500, across 494 job postings as of November 2026.
  • Tarmac last reviewed these Terraform interview questions on 3 December 2026.

At a glance

Questions10 shown · 25 in the bank
Difficulty1–4 of 5
FormatsMultiple choice, Fill in the blank, True / false, Design exercise, Multiple answer

What you'll review

  1. input variables
  2. module composition

Practice questions

Try one before you open the answer. Pick an option and press Check; it's marked on the spot.

In a Terraform module, which block type is used to declare an input variable named environment?#

Options

Show answer

Terraform declares input variables with a variable block, for example variable "environment" { type = string }. The block's label is the variable name and its body defines the type, default value, and description. Terraform has no input, param, or argument block types.

Why:

Terraform uses the variable block type to define input variables in a module. Each variable block includes a name label (e.g., "environment") and a body containing attributes like type, default, and description. There is no input, param, or argument block type in the Terraform configuration language.

In Terraform, when you reference an output value from a child module, you use the syntax module.<MODULE_NAME>.<OUTPUT_NAME>. The keyword used to declare a module block is _____.#

Show answer

In Terraform, when you reference an output value from a child module, you use the syntax module.<MODULE_NAME>.<OUTPUT_NAME>. The keyword used to declare a module block is module.

Why:

A child module is invoked in Terraform configuration using a module block. The label after module becomes the logical name you use to reference that module instance's outputs via module.<MODULE_NAME>.<OUTPUT_NAME>.

In Terraform, if a child module declares an input variable with no default argument, the calling module block must supply a value for that variable, or terraform plan fails with an error.#

Options

Show answer

Yes. A Terraform child module variable with no default is required, so the calling module block must pass a value for it. Otherwise validation and terraform plan fail with a "Missing required argument" error. Child module variables only get values from the arguments in the module block, so Terraform cannot prompt for them. Adding a default makes the variable optional.

Why:

An input variable with no default is a required variable. For a child module, the only place a value can come from is the arguments in the calling module block. Terraform does not prompt for child module variables, and it does not read -var flags or .tfvars files for them. If the argument is left out, Terraform reports a "Missing required argument" error when it validates or plans the configuration. Adding a default (even default = null) makes the variable optional.

In Terraform 1.x, a child module can directly read a variable declared in its calling (parent) module, such as var.region, without that value being passed in as an argument to the module block.#

Options

Show answer

No. A Terraform child module cannot read its parent's variables directly. Each module has its own scope, so the parent has to pass values in as arguments on the module block, and the child has to declare matching variable blocks. Data goes back to the parent only through the child's output values, which the parent reads as module.<name>.<output>.

Why:

Each Terraform module has its own namespace. A child module can only see its own input variables, locals, and resources. If a child needs a value from its parent, the parent has to pass it in explicitly as an argument on the module block (for example region = var.region), and the child has to declare a matching variable "region" block. Values travel back up the other way only through the child's output blocks. Because of this explicit wiring, the statement is false.

In the root module of a Terraform configuration (the directory where you run terraform plan directly), the following input variable is declared:#

Options

Show answer

Terraform prompts for the value interactively. A root-module input variable with no default is required. If no value comes from -var, -var-file, *.auto.tfvars, or TF_VAR_*, and the terminal is interactive, Terraform asks for the value at the prompt instead of inventing zero, null, or skipping it.

Why:

In the root module, an input variable declared without a default is required. The standard value sources (-var, -var-file, *.auto.tfvars, and TF_VAR_* environment variables) are all checked, and when none supplies a value, Terraform with default input settings in an interactive terminal prompts the user to enter one. Terraform does not substitute a zero-value or null, and it does not silently drop the variable; the type constraint only validates a value that is supplied. (In a non-interactive run with -input=false or no terminal, the same situation instead produces a hard error.)

In Terraform 1.x, a root module can pass an entire child module's outputs to another module as a single input. For example, vpc = module.network works if the receiving module declares a variable "vpc" with a suitable object(...) type, or with type any.#

Options

Show answer

Yes. In Terraform 1.x, module.network on its own evaluates to an object containing all of that module's outputs. That object can be passed to another module's input variable whose type is a matching object({...}) or any. With an object type, any attributes that aren't declared are discarded during conversion. This lets you compose modules by passing a whole interface at once instead of wiring outputs one by one.

Why:

Since Terraform 0.13, module.<name> with no attribute after it is an expression whose value is an object holding all of that module's outputs. You can assign that object to another module's input variable, as long as the variable's type constraint accepts it. An object({...}) type that lists the outputs you need works, and so does any. With an object type, any extra attributes are dropped during type conversion. This pattern shows up often in module composition: one module's whole interface is passed to another, so you don't have to wire up each output separately.

You have the following variable declaration in a Terraform module:#

Options

Show answer

The plan fails with the error message "Instance type must start with t[0-9]." Terraform evaluates variable validation blocks during terraform plan for every value source — caller-provided or default. Since regex("^t[0-9]", "m5.large") errors on no match, can() returns false, the condition fails, and the declared error_message is shown.

Why:

Terraform variable validation runs whenever the variable's value is resolved, regardless of whether the value comes from the caller or the default. During terraform plan, the caller-supplied value "m5.large" is evaluated against the condition. The regex("^t[0-9]", "m5.large") call throws an error because the pattern finds no match; can() catches that error and returns false, making the overall condition false. When the condition is false, Terraform surfaces the error_message and halts the plan. The claim that validation only runs when the caller omits the variable and the default is used is wrong because validation applies to all value sources. The claim that validation is only evaluated during terraform apply, not terraform plan is wrong because validation runs during plan, not only apply. The claim that can() always returns true when wrapping regex(), so the condition is always true and the validation never fires is wrong because can() returns false when the wrapped expression errors, which is exactly what happens here.

Design the Terraform repository structure and state strategy for a service that must be deployed identically to dev, staging, and prod on AWS.#

Show answer

Module factoring. One shared module (modules/service) encodes the infrastructure shape. Each environment is its own root configuration (environments/dev, /staging, /prod) that calls the shared module and passes per-env inputs (instance size, replica count, domain) as variables. The shape is defined once; environments differ only in inputs, so they stay DRY without branching on var.env with conditionals.

State isolation. Each environment root has its own backend state — e.g. the same S3 bucket with a distinct key (dev/terraform.tfstate, prod/terraform.tfstate) or separate buckets/accounts. Because Terraform only ever sees one environment's state at a time, a dev plan/apply physically cannot reference or destroy prod objects. Blast radius is bounded by the state boundary.

Backend & locking. Remote backend (S3 with native lockfile or DynamoDB, or Terraform Cloud) with locking so concurrent applies serialize and can't corrupt state, plus encryption at rest. No local state for a team.

Secrets. No secrets in .tf or committed tfvars. Pull them from a secret manager (SSM/Secrets Manager) via data sources, or inject as CI/TF_VAR variables. Note that any value used still ends up in plaintext state, so state access control and encryption — not sensitive = true — are the real protection.

Workflow. CI runs terraform plan on every PR and posts it for review; on merge it applies the reviewed plan per environment, promoting dev → staging → prod. Providers and the shared module are version-pinned (and a committed lock file) for reproducibility.

Tradeoffs. Directory-per-environment is explicit and isolates state cleanly at the cost of some repetition in the thin root configs. Terraform workspaces keep one config + one backend and switch state by workspace — lighter, but it's dangerously easy to apply to the wrong workspace and they share backend config, so they suit ephemeral/per-developer copies more than long-lived dev/staging/prod. Full duplication of the module per env is the worst of both: lots of drift, no single source of truth.

Why:

The signal is whether the candidate isolates state per environment (the real safety boundary that stops dev from touching prod) and keeps things DRY via a shared module with per-env inputs — rather than duplicating config or branching on an env variable. Strong answers add a remote locking backend, secrets sourced outside source control with the caveat that state is plaintext, a plan-on-PR/apply-on-merge flow, and an honest comparison with workspaces (convenient but easy to misfire). This separates people who've operated multi-environment Terraform from those who've only run a single config.

A parent module retrieves a database password from AWS Secrets Manager and passes it to a child module:#

Options

Show answer

A sensitive value passed into a child module stays sensitive inside that module, so resource arguments using it are redacted in plan output. An output that returns the value must be declared with sensitive = true; otherwise Terraform fails with 'Output refers to sensitive values' instead of exposing the password.

Why:

Sensitivity is a property of the value, and it propagates across module boundaries. The secret passed into the module call is sensitive, so var.db_password remains sensitive in the child module even though the variable block omits sensitive = true; the resource argument is therefore redacted in plan output. Terraform 0.15 and later do not auto-mark outputs: an output whose expression depends on a sensitive value must be declared sensitive = true, and if it is not, Terraform fails with 'Output refers to sensitive values'. The module call itself does not produce a validation error, so the error comes from the unmarked output rather than from the input variable. The option claiming the password is shown in plaintext is wrong because the value is sensitive and redacted; the option claiming sensitivity is limited to the resource argument is wrong because the value's sensitivity does not depend on the reference site.

In Terraform 1.x, you are refactoring a root configuration. Which of the following statements about module composition are true? Select all that apply.#

Options

Pick every one that applies.

Show answer

In Terraform 1.x, a module with its own provider block can't use count, for_each, or depends_on. Module-level depends_on makes everything in the module wait for the whole target module, which can push data source reads to apply time. moved blocks move resources into child modules and keep their state. Modules can't reference sibling modules directly, and outputs only go up one level, so they must be re-exported by each intermediate module.

Why:

Terraform rejects count, for_each, and depends_on on a module that contains its own provider configuration, which is why such modules are called legacy modules. Module-level depends_on turns into a dependency of everything inside the module on everything in the target module. That can push data source reads to apply time and leave values unknown during plan. moved blocks can move resources across module boundaries and keep their state. Module namespaces are isolated, so a child cannot reference module.sibling directly. Values have to be passed in as input variables. Outputs only go up one level at a time, so a grandchild's output must be re-exported by the module between it and the root.

Related interview questions

Job market

See terraform salaries and hiring demand from live job postings.

The other 15 questions

This page shows 10 and marks what you pick. That's as far as a page can go. A free account opens the other 15 and keeps every answer. What you miss comes back until it's right: after a day, then at longer gaps.

Start with this topic

Free · the whole bank · 100 answers per 30 days, each marked with written feedback

Interview booked? Practise the job ad instead

What moved, monthly

One email a month when the bulletin comes out: what moved in the markets we track, and the new question topics we published. Confirm your address to join. Unsubscribe any time.