5 questions

Modules & Configuration

What is a Terraform module?

  • a.A command-line flag that enables debug logging
  • b.A remote service that stores state
  • c.A container for multiple resources that are used together, defined as a set of configuration files
  • d.A special provider that only manages networking

A module is a reusable container for a group of related resources defined in a set of .tf files. Every configuration has a root module, and it can call child modules to organize and reuse code. Modules are not CLI flags, state backends, or providers.

Modules & Configuration

You want to pass a value into a module and receive a computed value back out. Which pair of constructs do you use?

  • a.provisioners for input and locals for output
  • b.input variables for values passed in and outputs for values returned
  • c.data sources for input and providers for output
  • d.backends for input and workspaces for output

Input variables (variable blocks) define the values a module accepts, and output values (output blocks) expose results from the module to its caller. Locals are internal helpers, data sources read existing information, and providers configure plugins, none of which serve as the module's public input/output interface.

Modules & Configuration

Which Terraform construct reads information about existing infrastructure that Terraform does not manage, for use elsewhere in your configuration?

  • a.A data source
  • b.A resource block
  • c.An output value
  • d.A variable block

A data source (data block) fetches information about existing objects, such as an AMI ID or an existing VPC, so it can be referenced in configuration without Terraform managing that object. resource blocks create and manage objects, outputs expose values, and variables accept inputs.

Modules & Configuration

You need to create several nearly identical resources that differ by a value from a list. Which meta-argument iterates over a collection to create one resource instance per element with a stable key?

  • a.depends_on
  • b.provider
  • c.lifecycle
  • d.for_each

for_each creates one instance per element of a map or set, keying instances by their map key or set value, which keeps instances stable when the collection changes. count also creates multiple instances but keys by numeric index, which can cause churn. depends_on, provider, and lifecycle serve other purposes.

Modules & Configuration

How does Terraform decide the order in which to create resources when one resource references another's attribute?

  • a.It always creates resources alphabetically by name
  • b.It builds a dependency graph from references and creates dependencies first
  • c.It creates them in the order they appear in the file, top to bottom
  • d.It creates all resources simultaneously regardless of dependencies

Terraform builds a dependency graph by analyzing references between resources; when resource B uses an attribute of resource A, Terraform creates A before B automatically. This implicit dependency handling is why explicit ordering is rarely needed. depends_on is only for dependencies Terraform cannot infer.

Report