SaveMyCert
Log in
5 of 5 free questions left today·for 10 a day
Terraform Pro 002 · Domain 4

CI/CD and automation workflows practice questions

CI/CD and automation workflows is worth 10% of the Terraform Pro 002 exam — the 6th-heaviest of the 7 domains. Running Terraform in pipelines: pipeline functionality, deployment strategies, dynamic provider credentials and variable files. Weight approximates the sub-objective share. 6 fully worked examples are further down this page, answers included.

Exam weight
10%
the 6th-heaviest of the 7 domains
Questions
79
across 2 topics
Free, no account
5/day
a free account allows 10 a day
Explanations
Every option
right and wrong

Build a practice session

5 free questions left today.

Domains

How many?

Mode

Ready when you are

10 fresh questions drawn across 1 of 7 domains, in Learn mode.

Review what you missed

Every question you answer incorrectly, and every question you flag while practising, is saved here automatically. Finish a session and you can come back to re-drill just those.

6 sample CI/CD and automation workflows questions, fully explained

Questions from the Terraform Pro 002 bank mapped to domain 4, with the answer key and the reasoning behind every option. None of them repeat the examples on the main Terraform Pro 002 practice page.

Question 1CI/CD and automation workflows

A team's lint job runs terraform fmt -check in the repository root and has passed on every pull request for months. A reviewer now finds that several files in modules/network/ use inconsistent indentation and alignment. The job's log shows no errors. What explains the missed files?

Choose one.

  • a
    fmt -check only reports files changed in the current commit

    fmt has no notion of commits; it checks every .tf file in the directories it processes.

  • b
    fmt -check reports problems but always exits with status zero

    -check exits non-zero when any input is unformatted; that is what makes it usable as a gate.

  • c
    fmt only processes the current directory unless -recursive is set Correct

    Without -recursive fmt examines only the given or current directory, so files in modules/network/ were never checked.

  • d
    fmt skips files in directories that hold a module's own versions.tf

    fmt has no such rule; module directories are processed like any other once fmt is told to recurse.

The concept

terraform fmt's scope: by default only the specified or current directory.

Why that’s the answer

The documentation states that by default fmt only processes the specified or current directory, and -recursive also processes subdirectories. The job therefore checked only the root's .tf files. -check does return a non-zero exit status on findings, and fmt has no commit-aware or module-aware filtering.

How to reason it out
  1. Note where the job runs and where the bad files live.
  2. Recall fmt's default scope is one directory.
  3. Recall -check does fail the job on findings it sees.
  4. Conclude the files were outside the scope; add -recursive.

Exam tip: No -recursive, no subdirectories: fmt -check from the root misses modules/.

Terraform Professional: CI/CD Pipelines and Deployment Strategies — the lesson that teaches this.

Question 2CI/CD and automation workflows

A build host runs up to eight Terraform jobs at the same time. To avoid downloading providers on every run, every job sets TF_PLUGIN_CACHE_DIR to the same shared directory. When several jobs start together, terraform init sometimes fails with errors about incomplete or unreadable provider packages. What should the team change?

Choose one.

  • a
    Set TF_PLUGIN_CACHE_MAY_BREAK_DEPENDENCY_LOCK_FILE in each job

    That option only lets Terraform use cached packages without matching lock-file checksums; it does nothing for concurrent writes.

  • b
    Run terraform init -upgrade so each job refreshes the shared cache

    -upgrade makes init look for newer versions, which adds more writes to the shared cache rather than fewer.

  • c
    Move the cache setting from the variable to a CLI config file

    plugin_cache_dir in the CLI configuration file behaves the same as the variable; the shared directory remains.

  • d
    Give each concurrently running job its own plugin cache directory Correct

    The plugin cache is not guaranteed to be concurrency safe, so parallel inits must not share one cache directory.

The concept

The provider plugin cache saves downloads, but HashiCorp does not guarantee it is safe for concurrent terraform init runs.

Why that’s the answer

The CLI configuration documentation states that the plugin cache directory is not guaranteed to be concurrency safe and that the installer's behaviour with multiple concurrent terraform init calls is undefined. Separate caches per concurrent job (or a pre-populated read-only provider directory) remove the race. The lock-file option and -upgrade address different problems, and moving the setting to a file changes nothing about sharing.

How to reason it out
  1. Notice the failures happen only when jobs start together.
  2. Recall that the plugin cache is not guaranteed to be concurrency safe.
  3. Pick the change that stops parallel inits writing the same cache.

Exam tip: One plugin cache per concurrent init; the cache is not concurrency safe.

Terraform Professional: CI/CD Pipelines and Deployment Strategies — the lesson that teaches this.

Question 3CI/CD and automation workflows

CI jobs start in fresh containers with a persistent volume mounted as TF_PLUGIN_CACHE_DIR, and the cache already holds every provider the repositories use. The repositories do not commit .terraform.lock.hcl, so each job's init creates it. Logs show every job still downloading providers from the registry. The team wants cache hits while lock files keep checksums valid on every platform. What should it do?

Choose one.

  • a
    Set TF_PLUGIN_CACHE_MAY_BREAK_DEPENDENCY_LOCK_FILE=1 on each CI job

    This allows cache use, but the new lock entries hold only the cached package's checksum, so they may be invalid on other platforms.

  • b
    Run terraform init -upgrade so that init prefers the cached packages

    -upgrade asks init to select the newest allowed versions; it does not make a missing lock entry trust the cache.

  • c
    Set plugin_cache_dir in a CLI config file instead of the env variable

    The file setting is equivalent to the variable, so the cache is still bypassed when there is no lock entry.

  • d
    Commit the lock file that terraform init generates to each repository Correct

    With a committed lock entry, init can reuse a cached package that matches a recorded checksum instead of going upstream.

The concept

The plugin cache is used only when a cached package matches a checksum already recorded in the dependency lock file.

Why that’s the answer

HashiCorp's documentation says Terraform always installs a provider from upstream the first time it is used with a configuration, so that it can record a complete set of checksums; later runs reuse the cache once the lock file has them. Without a committed lock file every run is a 'first time'. The may-break option would produce cache hits but writes an incomplete lock entry valid only for the current OS and architecture, which breaks the stated cross-platform requirement.

How to reason it out
  1. Ask why a populated cache is ignored: there is no lock entry to match.
  2. Recall that a first install goes upstream to record full checksums.
  3. Reject the may-break option: it trades away cross-platform checksums.
  4. Commit the lock file so later inits can match the cache.

Exam tip: No lock entry, no cache hit: commit .terraform.lock.hcl to make the plugin cache work safely.

Terraform Professional: CI/CD Pipelines and Deployment Strategies — the lesson that teaches this.

Question 4CI/CD and automation workflows

A GitHub Actions job installs Terraform with hashicorp/setup-terraform using its default inputs. A later step in the same job runs terraform output -json > outputs.json, and the next step's jq command fails because the file contains extra lines around the JSON. Which change should the team make?

Choose one.

  • a
    Add -no-color to the terraform output -json call

    -no-color strips colour codes only; the extra lines come from the wrapper around the binary.

  • b
    Pin the action's terraform_version input to 1.15.0

    Pinning the CLI version is good practice but does not remove the wrapper, which is installed for any version.

  • c
    Replace the call with terraform output -raw outputs

    -raw accepts only one named primitive output, and the wrapper would still be in the call path.

  • d
    Set the action's terraform_wrapper input to false Correct

    The default wrapper intercepts each terraform call to capture its streams; turning it off leaves plain Terraform output for redirection.

The concept

hashicorp/setup-terraform installs, by default, a wrapper that captures each terraform call's stdout, stderr and exit code as step outputs.

Why that’s the answer

terraform_wrapper defaults to true. The wrapper runs subsequent terraform calls and records their results so later steps can read steps.<id>.outputs.stdout, stderr and exitcode. When a step needs Terraform's own output on stdout, for example JSON piped to jq, set terraform_wrapper: false; the README notes it can be skipped when later steps do not need the captured results.

How to reason it out
  1. Note that the extra content appears only when Terraform runs under the action.
  2. Recall that setup-terraform wraps the binary by default.
  3. Disable the wrapper when scripts consume Terraform's raw output.

Exam tip: Piping terraform output in GitHub Actions? Set terraform_wrapper: false.

Terraform Professional: CI/CD Pipelines and Deployment Strategies — the lesson that teaches this.

Question 5CI/CD and automation workflows

A pipeline uses the CLI-driven workflow with a cloud block whose hostname is tfe.example-corp.com, a Terraform Enterprise instance. The runner must authenticate with an API token supplied as an environment variable, without writing a CLI configuration file. Which variable name does Terraform read for that host?

Choose one.

  • a
    TF_TOKEN_tfe_example_corp_com

    A single underscore stands for a period, so this names the host tfe.example.corp.com.

  • b
    TF_TOKEN_tfe_example__corp_com Correct

    Periods in the host name become single underscores and the hyphen may be encoded as a double underscore.

  • c
    TF_TOKEN_tfe_example-corp_com

    A hyphen is valid in a host name but usually not in an environment variable name, so shells reject this.

  • d
    TF_TOKEN_tfe_example__corp__com

    The second double underscore encodes a hyphen, so this names tfe.example-corp-com rather than the real host.

The concept

Terraform 1.2 and later read host credentials from TF_TOKEN_<host> environment variables, with the host name encoded for variable-name rules.

Why that’s the answer

The CLI configuration documentation says the variable name is TF_TOKEN_ plus the domain name with periods encoded as underscores, and that hyphens, which are usually invalid in variable names, may be encoded as double underscores. tfe.example-corp.com therefore becomes TF_TOKEN_tfe_example__corp_com. Using a single underscore for the hyphen produces a different host, and the full host name including the tfe label is required.

How to reason it out
  1. Start from the full host name: tfe.example-corp.com.
  2. Encode each period as one underscore.
  3. Encode the hyphen as a double underscore.
  4. Prefix with TF_TOKEN_.

Exam tip: TF_TOKEN_<host>: periods become _, hyphens become __.

Terraform Professional: CI/CD Pipelines and Deployment Strategies — the lesson that teaches this.

Question 6CI/CD and automation workflows

A monorepo holds envs/prod/ (the prod root module) and modules/ (local modules that envs/prod/ calls with relative paths), plus docs/ and other teams' folders. The VCS-driven prod workspace uses envs/prod as its working directory. It must queue runs for changes to envs/prod/ or modules/ and ignore every other push. How should the workspace's run triggering be set?

Choose one.

  • a
    Only trigger on specified paths: /envs/prod/**/* and /modules/**/* Correct

    Glob trigger patterns cover both the root module and the local modules it reads, and nothing else queues a run.

  • b
    Only trigger on specified paths, with the pattern /envs/prod/**/*

    Changes to modules/ alter what prod deploys, yet this pattern would never queue a run for them.

  • c
    Always trigger runs, with envs/prod set as the workspace working directory

    Always trigger queues a run for a push to any file in the repository, including docs/ and other teams' folders.

  • d
    Git tag triggers, with a semantic versioning tag format selected

    Tag triggers queue runs only for matching tags, so ordinary merges to envs/prod/ or modules/ would not run.

The concept

VCS-driven workspaces can limit automatic runs to changes that affect specified paths, preferably with glob trigger patterns.

Why that’s the answer

With 'Only trigger runs when files in specified paths change', HCP Terraform begins runs only for changes that affect the specified files and directories; HashiCorp recommends glob trigger patterns. Because envs/prod calls modules/ through relative paths, both trees must be listed, or a module change would reach prod only on some unrelated later run. 'Always trigger' reacts to any file in the repository, and tag triggers ignore ordinary pushes.

How to reason it out
  1. List what can change prod's plan: its root module and the local modules.
  2. Exclude everything else, so 'Always trigger' is out.
  3. Choose specified paths with patterns covering both trees.

Exam tip: Path-filtered triggers must include every local module the workspace reads, not just its working directory.

Terraform Professional: CI/CD Pipelines and Deployment Strategies — the lesson that teaches this.

What Terraform Pro 002 domain 4 tests, topic by topic

The official exam guide breaks CI/CD and automation workflows into 2 topics. The question bank follows the same split, so a weak topic shows up as a cluster of misses you can go back and read.

Published Terraform Pro 002 practice questions per topic in CI/CD and automation workflows
TopicWhat it coversQuestions
CI/CD pipelines and deployment strategiesOfficial Terraform Infrastructure Engineer Professional (002) objectives, 4a Manage CI/CD pipeline functionality; 4b Understand deployment strategies.40
Dynamic provider credentials and variable filesOfficial Terraform Infrastructure Engineer Professional (002) objectives, 4c Manage multiple sets of dynamic provider credentials across teams, projects, and workspaces; 4d Overwrite Terraform variables using auto.tfvars / .tfvars.39
Total79

Revise CI/CD and automation workflows before you drill it

Other Terraform Pro 002 domains

CI/CD and automation workflows: your questions

CI/CD and automation workflows is domain 4 of the Terraform Pro 002 exam guide and carries 10% of the scored content — the 6th-heaviest of the 7 domains. HashiCorp has not yet published the exam's question count, so there is no per-domain number of questions to give.

Source

The domain weight and topic list on this page come from the official Terraform Pro 002 exam guide.