Skip to content

002 · Domain 3: Infrastructure Lifecycle and Operations · 22% of the exam

Task 3.1: Manage and scale infrastructure projects

Growing past one root module: splitting state by blast radius and ownership, local and shared modules, backend configuration per project, and when CLI workspaces fit and when they do not.

Study it

  • Splitting projects by blast radius, ownership and state

    Lesson coming

Sample questions

Try each one before opening the answer. Every option is explained, with the HashiCorp documentation page that proves it.

Question 1 · choose 1

A monolithic configuration is being split into network, data and application configurations, each with its own state. The application servers are stateless and sit behind a load balancer that tolerates replacement; the production database cannot be recreated. The team runs Terraform 1.15 and wants every step reviewable in a plan. Which migration approach follows HashiCorp's guidance?

  1. ARecreate the app servers in the new configuration; move the database with removed and import blocks
  2. BMove every resource, the database and servers included, with terraform state mv -state and -state-out
  3. CKeep one configuration and use CLI workspaces named network, data and app
  4. DCopy the state file into each new backend, then prune each copy with terraform state rm until it fits
Show the answer and why
  • ARecreate the app servers in the new configuration; move the database with removed and import blocks

    Correct

    HashiCorp recommends recreating stateless resources when that causes no downtime, and moving stateful ones with a removed block (destroy = false) in the source and an import block in the destination, both visible in plans.

  • BMove every resource, the database and servers included, with terraform state mv -state and -state-out

    Incorrect

    state mv between state files is the legacy approach and changes state outside the plan and apply workflow, so the moves are not reviewable.

  • CKeep one configuration and use CLI workspaces named network, data and app

    Incorrect

    Workspaces are not a tool for system decomposition; each component should have its own configuration and backend.

  • DCopy the state file into each new backend, then prune each copy with terraform state rm until it fits

    Incorrect

    Copying state duplicates every binding first and depends on manual pruning outside plans, which risks two configurations managing one object.

Group resources by rate of change, statefulness and ownership. Recreate what is cheap and safe to recreate, and use removed and import blocks (Terraform 1.7 or later) for objects that must survive the move.

Question 2 · choose 1

A platform team keeps five shared modules and the production configurations that call them in one repository. Following the HashiCorp style guide, how should it store the modules?

  1. AEach module in its own repository, apart from the infrastructure configuration
  2. BAll modules in a modules/ folder of the production configuration
  3. COne repository holding every module, tagged with a single version
  4. DInside the .terraform directory, copied in by terraform init
Show the answer and why
  • AEach module in its own repository, apart from the infrastructure configuration

    Correct

    The style guide recommends storing infrastructure configuration separately from module code and keeping each module in an individual repository, so each one can be versioned and published on its own.

  • BAll modules in a modules/ folder of the production configuration

    Incorrect

    Local modules share their caller's version and cannot be versioned or published independently.

  • COne repository holding every module, tagged with a single version

    Incorrect

    A shared tag forces every module to release together.

  • DInside the .terraform directory, copied in by terraform init

    Incorrect

    .terraform is a local directory that init manages for one working directory, not a place to keep shared code.

Separate module repositories let teams version each module independently and publish it to a private registry.

Question 3 · choose 1

An organization debates moving all modules and infrastructure configuration into one monolithic repository. Which drawback does the HashiCorp style guide point out?

  1. AThe registry cannot publish any module that is stored in a monorepo
  2. BTerraform cannot read local modules from another directory
  3. CCI must target changed directories, and access is less granular
  4. DState for every directory must live in one state file for the repo
Show the answer and why
  • AThe registry cannot publish any module that is stored in a monorepo

    Incorrect

    The style guide mentions module publishing for separate repositories, but the drawback it lists for monorepos concerns automation and access.

  • BTerraform cannot read local modules from another directory

    Incorrect

    Root modules in a monorepo routinely call local modules by relative path.

  • CCI must target changed directories, and access is less granular

    Correct

    Any change can trigger a deployment for the whole repository unless the workflow targets modified directories, and repository access is not scoped per component.

  • DState for every directory must live in one state file for the repo

    Incorrect

    Each root module in a monorepo still has its own state.

If a monorepo is required, HCP Terraform and Terraform Enterprise can scope each workspace to a directory of the repository.

Question 4 · choose 1

A monorepo holds network/, data/ and app/, and each HCP Terraform workspace sets its working directory to one of them. In a CLI-driven workspace, an engineer runs terraform plan from inside app/. What does Terraform upload?

  1. AOnly the app/ directory that the command runs in
  2. Bapp/ plus the local modules it calls by path
  3. COnly the files changed since the last run
  4. DThe entire combined configuration directory
Show the answer and why
  • AOnly the app/ directory that the command runs in

    Incorrect

    With a combined repository and workspace working directories, the upload is not limited to the directory you run from.

  • Bapp/ plus the local modules it calls by path

    Incorrect

    Terraform does not work out which files a configuration needs; it uploads the combined configuration directory.

  • COnly the files changed since the last run

    Incorrect

    CLI-driven runs upload an archive of the configuration directory, not a diff.

  • DThe entire combined configuration directory

    Correct

    Whether you run from the real working directory or the root of the combined configuration directory, Terraform uploads the entire combined configuration directory.

In a large monorepo every CLI-driven run uploads everything, so keep large unrelated files out of the configuration directory or exclude them from the upload.

Question 5 · choose 1

To add a production copy of a stack, an engineer copies dev.tf to prod.tf in the same directory and changes a few values, leaving the resource names unchanged. What happens on the next terraform validate?

  1. ATerraform loads only the newest file in the directory
  2. BIt fails with duplicate declarations from the merged files
  3. Cprod.tf overrides dev.tf as the later file alphabetically
  4. DTerraform creates two separate states, one per file
Show the answer and why
  • ATerraform loads only the newest file in the directory

    Incorrect

    Terraform loads all configuration files in a directory.

  • BIt fails with duplicate declarations from the merged files

    Correct

    Terraform appends every file in the directory together, so resources with the same name collide.

  • Cprod.tf overrides dev.tf as the later file alphabetically

    Incorrect

    Ordinary files are not override files, so neither one replaces the other.

  • DTerraform creates two separate states, one per file

    Incorrect

    State belongs to the working directory, not to each file.

Separate environments into their own directories or workspaces instead of adding parallel files to one directory.

Practice domain 3 →Practice all domains →