HashiCorp Terraform Associate 004 (HashiCorp Certified: Terraform Associate (004)) Practice Test 107

Question 1060

A Terraform 1.12 configuration evaluates element(distinct(["dev", "prod", "dev", "qa"]), 4). Which result follows from the expression as written?

  1. "prod"
  2. "dev"
  3. "qa"
  4. "index out of range"

Explanation

Correct Answer

A:

For the specific expression element(distinct(["dev", "prod", "dev", "qa"]), 4), First, distinct keeps each distinct value at its first occurrence; The list has 3 entries, so element wraps index 4 modulo 3 and selects zero-based position one.

Incorrect Answers

B:

For the concrete expression element(distinct(["dev", "prod", "dev", "qa"]), 4), index wraparound lands at position one, not the first position of the inner list; the inner stage produces ["dev", "prod", "qa"] before the outer operation is applied.

C:

For the concrete expression element(distinct(["dev", "prod", "dev", "qa"]), 4), the final list member is not selected; the effective index is one; the inner stage produces ["dev", "prod", "qa"] before the outer operation is applied.

D:

For the concrete expression element(distinct(["dev", "prod", "dev", "qa"]), 4), element wraps a positive index instead of failing like ordinary square-bracket indexing; the inner stage produces ["dev", "prod", "qa"] before the outer operation is applied.

Question 1061

The team is documenting risks of Formatting and code review noise while planning to reduce insignificant whitespace changes across developers. Which caveat specifically applies to that mechanism?

  1. A formatted file can still describe unsafe infrastructure operations.
  2. It does not fetch remote modules to reformat their source repositories.
  3. Operators should still review unexpected source diffs from any automated formatter.
  4. Formatting does not validate external credentials or apply changes.

Explanation

Correct Answer

A:

For Formatting and code review noise in the task to reduce insignificant whitespace changes across developers, the important caution is: A formatted file can still describe unsafe infrastructure operations. The reason this matters is its actual behavior: Canonical formatting minimizes differences due solely to manual layout preferences.

Incorrect Answers

B:

The proposed warning belongs to terraform fmt -recursive, which serves the different goal to format Terraform configurations in nested local directories, rather than to Formatting and code review noise: The recursive flag expands formatting beyond just the current directory. The question concerns Formatting and code review noise acting to reduce insignificant whitespace changes across developers, not a limit of terraform fmt -recursive.

C:

The proposed warning belongs to Formatting preserved semantics, which serves the different goal to change whitespace and presentation without intending resource changes, rather than to Formatting and code review noise: terraform fmt standardizes language presentation instead of performing infrastructure reconciliation. The question concerns Formatting and code review noise acting to reduce insignificant whitespace changes across developers, not a limit of Formatting preserved semantics.

D:

The listed caution belongs specifically to terraform fmt command, used to rewrite Terraform configuration into its canonical layout: terraform fmt formats Terraform language files consistently, including spacing and alignment; the feature under review is instead Formatting and code review noise, so this answer attaches another feature's qualification to the wrong mechanism.

Question 1062

A Terraform 1.12 configuration evaluates slice(distinct(["dev", "prod", "dev", "qa"]), 1, 3). Which result follows from the expression as written?

  1. ["dev", "prod"]
  2. ["qa", "prod"]
  3. ["prod", "qa"]
  4. ["dev", "prod", "qa"]

Explanation

Correct Answer

C:

For the specific expression slice(distinct(["dev", "prod", "dev", "qa"]), 1, 3), First, distinct keeps each distinct value at its first occurrence; slice begins at zero-based index one and continues through the final member, stopping before the exclusive end index 3.

Incorrect Answers

A:

For the concrete expression slice(distinct(["dev", "prod", "dev", "qa"]), 1, 3), this takes an initial prefix rather than starting with the second entry; the inner stage produces ["dev", "prod", "qa"] before the outer operation is applied.

B:

For the concrete expression slice(distinct(["dev", "prod", "dev", "qa"]), 1, 3), slice preserves order rather than reversing the extracted portion; the inner stage produces ["dev", "prod", "qa"] before the outer operation is applied.

D:

For the concrete expression slice(distinct(["dev", "prod", "dev", "qa"]), 1, 3), this incorrectly keeps the first list member, although the slice begins at index one; the inner stage produces ["dev", "prod", "qa"] before the outer operation is applied.

Question 1063

An engineer tests the reverse behavior in terraform console. What is the result of reverse(["east", "west", "north"])?

  1. ["north", "east", "west"]
  2. ["north", "west", "east"]
  3. ["west", "north", "east"]
  4. ["east", "west", "north"]

Explanation

Correct Answer

B:

Evaluating the actual call reverse(["east", "west", "north"]): reverse reorders the three elements in the opposite sequence; it does not reorder text inside each element.

Incorrect Answers

A:

Given the specific operands supplied to the Terraform expression reverse(["east", "west", "north"]), the first and last swap in a three-member reversal, leaving west in the middle.

C:

Given the specific operands supplied to the Terraform expression reverse(["east", "west", "north"]), this rotates the list but does not reverse the order of all positions.

D:

Given the specific operands supplied to the Terraform expression reverse(["east", "west", "north"]), this keeps the original list order and ignores reverse.

Question 1064

A Terraform rollout has two separate requirements: first, reduce insignificant whitespace changes across developers; second, rewrite Terraform configuration into its canonical layout. Which assignment of mechanisms correctly handles both responsibilities?

  1. First use terraform fmt command; then use Formatting and code review noise.
  2. First use terraform fmt -check; then use terraform fmt -diff.
  3. First use Formatting and code review noise; then use terraform fmt command.
  4. First use Formatting and code review noise; then use terraform fmt -check.
  5. First use terraform fmt -diff; then use terraform fmt command.

Explanation

Correct Answer

C:

The first requirement, to reduce insignificant whitespace changes across developers, is handled by Formatting and code review noise: Canonical formatting minimizes differences due solely to manual layout preferences. The second requirement, to rewrite Terraform configuration into its canonical layout, is handled by terraform fmt command: terraform fmt formats Terraform language files consistently, including spacing and alignment. Each of these mechanisms has a distinct responsibility.

Incorrect Answers

A:

For the requested tasks to reduce insignificant whitespace changes across developers and rewrite Terraform configuration into its canonical layout, the first candidate terraform fmt command addresses rewrite Terraform configuration into its canonical layout; the second candidate Formatting and code review noise addresses reduce insignificant whitespace changes across developers. This mapping fails because the first mechanism primarily supports the task to rewrite Terraform configuration into its canonical layout and the second mechanism primarily supports the task to reduce insignificant whitespace changes across developers; the actual requirements are reduce insignificant whitespace changes across developers first and rewrite Terraform configuration into its canonical layout second.

B:

For the requested tasks to reduce insignificant whitespace changes across developers and rewrite Terraform configuration into its canonical layout, the first candidate terraform fmt -check addresses fail a style gate without modifying source files; the second candidate terraform fmt -diff addresses display differences that canonical formatting would introduce. This mapping fails because the first mechanism primarily supports the task to fail a style gate without modifying source files and the second mechanism primarily supports the task to display differences that canonical formatting would introduce; the actual requirements are reduce insignificant whitespace changes across developers first and rewrite Terraform configuration into its canonical layout second.

D:

For the requested tasks to reduce insignificant whitespace changes across developers and rewrite Terraform configuration into its canonical layout, the first candidate Formatting and code review noise addresses reduce insignificant whitespace changes across developers; the second candidate terraform fmt -check addresses fail a style gate without modifying source files. This mapping fails because the second mechanism primarily supports the task to fail a style gate without modifying source files; the actual requirements are reduce insignificant whitespace changes across developers first and rewrite Terraform configuration into its canonical layout second.

E:

For the requested tasks to reduce insignificant whitespace changes across developers and rewrite Terraform configuration into its canonical layout, the first candidate terraform fmt -diff addresses display differences that canonical formatting would introduce; the second candidate terraform fmt command addresses rewrite Terraform configuration into its canonical layout. This mapping fails because the first mechanism primarily supports the task to display differences that canonical formatting would introduce; the actual requirements are reduce insignificant whitespace changes across developers first and rewrite Terraform configuration into its canonical layout second.

Question 1065

A Terraform 1.12 configuration evaluates format("primary=%s", element(distinct(["dev", "prod", "dev", "qa"]), 0)). Which result follows from the expression as written?

  1. "secondary=dev"
  2. "primary=dev"
  3. "primary=prod"
  4. "dev"

Explanation

Correct Answer

B:

For the specific expression format("primary=%s", element(distinct(["dev", "prod", "dev", "qa"]), 0)), First, distinct keeps each distinct value at its first occurrence; element at zero selects the first member, and the single %s placeholder in format substitutes that member after the literal primary= prefix.

Incorrect Answers

A:

For the concrete expression format("primary=%s", element(distinct(["dev", "prod", "dev", "qa"]), 0)), the prefix is specified literally as primary= rather than secondary=; the inner stage produces ["dev", "prod", "qa"] before the outer operation is applied.

C:

For the concrete expression format("primary=%s", element(distinct(["dev", "prod", "dev", "qa"]), 0)), this uses the second list element; element at index zero selects the first value; the inner stage produces ["dev", "prod", "qa"] before the outer operation is applied.

D:

For the concrete expression format("primary=%s", element(distinct(["dev", "prod", "dev", "qa"]), 0)), the format string has a literal primary= prefix that must appear in the result; the inner stage produces ["dev", "prod", "qa"] before the outer operation is applied.

Question 1066

A reviewer is asked to choose a mechanism to change whitespace and presentation without intending resource changes. Which mechanism most directly meets this particular need?

  1. HCL style consistency in CI
  2. terraform fmt -recursive
  3. terraform fmt -diff
  4. terraform fmt -check
  5. Formatting preserved semantics
  6. terraform fmt command

Explanation

Correct Answer

E:

The task is to change whitespace and presentation without intending resource changes; Formatting preserved semantics directly supports that requirement: terraform fmt standardizes language presentation instead of performing infrastructure reconciliation. Its relevant boundary is: Operators should still review unexpected source diffs from any automated formatter.

Incorrect Answers

A:

HCL style consistency in CI is designed to make formatting a pre-merge quality gate, whereas this task is to change whitespace and presentation without intending resource changes: A pipeline can run fmt -check before validate and plan to enforce consistent source layout. Against Formatting preserved semantics, its limitation is: Style compliance alone cannot prove semantic correctness.

B:

terraform fmt -recursive is designed to format Terraform configurations in nested local directories, whereas this task is to change whitespace and presentation without intending resource changes: The recursive flag expands formatting beyond just the current directory. Against Formatting preserved semantics, its limitation is: It does not fetch remote modules to reformat their source repositories.

C:

terraform fmt -diff is designed to display differences that canonical formatting would introduce, whereas this task is to change whitespace and presentation without intending resource changes: terraform fmt -diff shows a style diff for files that need formatting. Against Formatting preserved semantics, its limitation is: A style diff is not an infrastructure change plan.

D:

terraform fmt -check is designed to fail a style gate without modifying source files, whereas this task is to change whitespace and presentation without intending resource changes: terraform fmt -check tests whether files are already formatted and returns an exit status. Against Formatting preserved semantics, its limitation is: The check does not fix configuration automatically.

F:

terraform fmt command is designed to rewrite Terraform configuration into its canonical layout, whereas this task is to change whitespace and presentation without intending resource changes: terraform fmt formats Terraform language files consistently, including spacing and alignment. Against Formatting preserved semantics, its limitation is: Formatting does not validate external credentials or apply changes.

Question 1067

For Terraform string processing with title casing, evaluate title("terraform associate"). Which output is correct?

  1. "Terraform Associate 004"
  2. "Associate Terraform"
  3. "Terraform Associate"
  4. "TerraformAssociate"

Explanation

Correct Answer

C:

Evaluating the actual call title("terraform associate"): title capitalizes the starts of the two words while preserving their separator and sequence.

Incorrect Answers

A:

Given the specific operands supplied to the Terraform expression title("terraform associate"), no additional 004 token appears in the source string, so title cannot append it.

B:

Given the specific operands supplied to the Terraform expression title("terraform associate"), the words remain in their original order rather than being reversed.

D:

Given the specific operands supplied to the Terraform expression title("terraform associate"), there is an existing space in the input, and title does not remove the word boundary.

Question 1068

A configuration walkthrough identifies "Formatting preserved semantics". Which task is it principally intended to support?

  1. fail a style gate without modifying source files
  2. display differences that canonical formatting would introduce
  3. change whitespace and presentation without intending resource changes
  4. rewrite Terraform configuration into its canonical layout

Explanation

Correct Answer

C:

The practical result of Formatting preserved semantics, used to change whitespace and presentation without intending resource changes, is: terraform fmt standardizes language presentation instead of performing infrastructure reconciliation. A qualification for this effect is: Operators should still review unexpected source diffs from any automated formatter.

Incorrect Answers

A:

That outcome applies to terraform fmt -check, intended to fail a style gate without modifying source files, rather than the question's feature Formatting preserved semantics: terraform fmt -check tests whether files are already formatted and returns an exit status. Unlike terraform fmt -check, Formatting preserved semantics is intended to change whitespace and presentation without intending resource changes, not to fail a style gate without modifying source files.

B:

That outcome applies to terraform fmt -diff, intended to display differences that canonical formatting would introduce, rather than the question's feature Formatting preserved semantics: terraform fmt -diff shows a style diff for files that need formatting. Unlike terraform fmt -diff, Formatting preserved semantics is intended to change whitespace and presentation without intending resource changes, not to display differences that canonical formatting would introduce.

D:

That outcome applies to terraform fmt command, intended to rewrite Terraform configuration into its canonical layout, rather than the question's feature Formatting preserved semantics: terraform fmt formats Terraform language files consistently, including spacing and alignment. Unlike terraform fmt command, Formatting preserved semantics is intended to change whitespace and presentation without intending resource changes, not to rewrite Terraform configuration into its canonical layout.

Question 1069

A Terraform 1.12 configuration evaluates length(concat(["app", "db"], ["cache"])). Which result follows from the expression as written?

  1. 1
  2. 3
  3. 4
  4. 2

Explanation

Correct Answer

B:

For the specific expression length(concat(["app", "db"], ["cache"])), First, concat appends the second list after the first; that produces exactly 3 elements; The outer length call counts those resulting elements rather than the original textual arguments.

Incorrect Answers

A:

In the calculation length(concat(["app", "db"], ["cache"])), 1 is not the size of the evaluated collection: the inner result has 3 elements, and length counts precisely those elements.

C:

For the concrete expression length(concat(["app", "db"], ["cache"])), this counts one element beyond the 3 values produced by the inner expression; the inner stage produces ["app", "db", "cache"] before the outer operation is applied.

D:

For the concrete expression length(concat(["app", "db"], ["cache"])), this drops one legitimate list element; the inner operation returns 3 values; the inner stage produces ["app", "db", "cache"] before the outer operation is applied.

Question 1070

A Terraform 1.12 configuration evaluates join("/", concat(["app", "db"], ["cache"])). Which result follows from the expression as written?

  1. "cache/db/app"
  2. "app/db/cache/cache"
  3. "app/db/cache"
  4. "appdbcache"

Explanation

Correct Answer

C:

For the specific expression join("/", concat(["app", "db"], ["cache"])), First, concat appends the second list after the first; The outer join uses a slash only between consecutive list members and preserves their computed order.

Incorrect Answers

A:

For the concrete expression join("/", concat(["app", "db"], ["cache"])), this reverses the members even though join preserves the order returned by the inner expression; the inner stage produces ["app", "db", "cache"] before the outer operation is applied.

B:

For the concrete expression join("/", concat(["app", "db"], ["cache"])), join must not repeat the last item after the list has been joined; the inner stage produces ["app", "db", "cache"] before the outer operation is applied.

D:

For the concrete expression join("/", concat(["app", "db"], ["cache"])), this omits the slash delimiters requested by join; the inner stage produces ["app", "db", "cache"] before the outer operation is applied.

HashiCorp Certified: Terraform Associate (004) (Terraform Associate 004) Practice Tests