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

Question 1120

A Terraform 1.12 configuration evaluates join("/", formatlist("%s-%d", ["app", "db"], [1, 2])). Which result follows from the expression as written?

  1. "app-1/db-2"
  2. "app-1db-2"
  3. "db-2/app-1"
  4. "app-1/db-2/db-2"

Explanation

Correct Answer

A:

For the specific expression join("/", formatlist("%s-%d", ["app", "db"], [1, 2])), First, formatlist formats the corresponding elements of both lists position by position; The outer join uses a slash only between consecutive list members and preserves their computed order.

Incorrect Answers

B:

For the concrete expression join("/", formatlist("%s-%d", ["app", "db"], [1, 2])), this omits the slash delimiters requested by join; the inner stage produces ["app-1", "db-2"] before the outer operation is applied.

C:

For the concrete expression join("/", formatlist("%s-%d", ["app", "db"], [1, 2])), this reverses the members even though join preserves the order returned by the inner expression; the inner stage produces ["app-1", "db-2"] before the outer operation is applied.

D:

For the concrete expression join("/", formatlist("%s-%d", ["app", "db"], [1, 2])), join must not repeat the last item after the list has been joined; the inner stage produces ["app-1", "db-2"] before the outer operation is applied.

Question 1121

A Terraform 1.12 configuration evaluates reverse(formatlist("%s-%d", ["app", "db"], [1, 2])). Which result follows from the expression as written?

  1. []
  2. ["db-2", "app-1"]
  3. ["app-1", "db-2"]
  4. ["db-2"]

Explanation

Correct Answer

B:

For the specific expression reverse(formatlist("%s-%d", ["app", "db"], [1, 2])), First, formatlist formats the corresponding elements of both lists position by position; reverse then returns the exact opposite element order, without sorting or removing members.

Incorrect Answers

A:

For the concrete expression reverse(formatlist("%s-%d", ["app", "db"], [1, 2])), reversing a nonempty list does not create an empty list; the inner stage produces ["app-1", "db-2"] before the outer operation is applied.

C:

For the concrete expression reverse(formatlist("%s-%d", ["app", "db"], [1, 2])), this leaves the inner result unchanged and skips the outer reverse call; the inner stage produces ["app-1", "db-2"] before the outer operation is applied.

D:

For the concrete expression reverse(formatlist("%s-%d", ["app", "db"], [1, 2])), the reverse function does not discard an element of the input list; the inner stage produces ["app-1", "db-2"] before the outer operation is applied.

Question 1122

A Terraform 1.12 configuration evaluates sort(formatlist("%s-%d", ["app", "db"], [1, 2])). Which result follows from the expression as written?

  1. ["app-1"]
  2. []
  3. ["app-1", "db-2"]
  4. ["db-2", "app-1"]

Explanation

Correct Answer

C:

For the specific expression sort(formatlist("%s-%d", ["app", "db"], [1, 2])), First, formatlist formats the corresponding elements of both lists position by position; Terraform sort then compares the resulting strings lexicographically in ascending order; it neither drops values nor preserves a non-sorted arrangement.

Incorrect Answers

A:

For the concrete expression sort(formatlist("%s-%d", ["app", "db"], [1, 2])), sorting does not remove the final element of the list; the inner stage produces ["app-1", "db-2"] before the outer operation is applied.

B:

For the concrete expression sort(formatlist("%s-%d", ["app", "db"], [1, 2])), the outer sort does not empty the nonempty collection; the inner stage produces ["app-1", "db-2"] before the outer operation is applied.

D:

For the concrete expression sort(formatlist("%s-%d", ["app", "db"], [1, 2])), a reversal is not guaranteed to produce ascending lexical order; the inner stage produces ["app-1", "db-2"] before the outer operation is applied.

Question 1123

A Terraform 1.12 configuration evaluates element(formatlist("%s-%d", ["app", "db"], [1, 2]), 3). Which result follows from the expression as written?

  1. "app-1"
  2. "index out of range"
  3. null
  4. "db-2"

Explanation

Correct Answer

D:

For the specific expression element(formatlist("%s-%d", ["app", "db"], [1, 2]), 3), First, formatlist formats the corresponding elements of both lists position by position; The list has 2 entries, so element wraps index 3 modulo 2 and selects zero-based position one.

Incorrect Answers

A:

For the concrete expression element(formatlist("%s-%d", ["app", "db"], [1, 2]), 3), index wraparound lands at position one, not the first position of the inner list; the inner stage produces ["app-1", "db-2"] before the outer operation is applied.

B:

For the concrete expression element(formatlist("%s-%d", ["app", "db"], [1, 2]), 3), element wraps a positive index instead of failing like ordinary square-bracket indexing; the inner stage produces ["app-1", "db-2"] before the outer operation is applied.

C:

For the concrete expression element(formatlist("%s-%d", ["app", "db"], [1, 2]), 3), element returns a known string from this nonempty computed list, not a null result; the inner stage produces ["app-1", "db-2"] before the outer operation is applied.

Question 1124

An engineer tests the anytrue behavior in terraform console. What is the result of anytrue([false, false, true])?

  1. 1
  2. false
  3. null
  4. true

Explanation

Correct Answer

D:

Evaluating the actual call anytrue([false, false, true]): anytrue becomes true when any list member is true; the final member satisfies that condition.

Incorrect Answers

A:

Given the specific operands supplied to the Terraform expression anytrue([false, false, true]), the result is the boolean true rather than integer one.

B:

Given the specific operands supplied to the Terraform expression anytrue([false, false, true]), only one true item is required, so the two false items do not force false.

C:

Given the specific operands supplied to the Terraform expression anytrue([false, false, true]), all inputs are known, so there is no unknown or null result.

Question 1125

A Terraform 1.12 configuration evaluates slice(formatlist("%s-%d", ["app", "db"], [1, 2]), 1, 2). Which result follows from the expression as written?

  1. []
  2. ["db-2"]
  3. ["app-1", "db-2"]
  4. ["app-1"]

Explanation

Correct Answer

B:

For the specific expression slice(formatlist("%s-%d", ["app", "db"], [1, 2]), 1, 2), First, formatlist formats the corresponding elements of both lists position by position; slice begins at zero-based index one and continues through the final member, stopping before the exclusive end index 2.

Incorrect Answers

A:

For the concrete expression slice(formatlist("%s-%d", ["app", "db"], [1, 2]), 1, 2), the final end index is exclusive, but the last element still lies before that boundary; the inner stage produces ["app-1", "db-2"] before the outer operation is applied.

C:

For the concrete expression slice(formatlist("%s-%d", ["app", "db"], [1, 2]), 1, 2), this incorrectly keeps the first list member, although the slice begins at index one; the inner stage produces ["app-1", "db-2"] before the outer operation is applied.

D:

For the concrete expression slice(formatlist("%s-%d", ["app", "db"], [1, 2]), 1, 2), this takes an initial prefix rather than starting with the second entry; the inner stage produces ["app-1", "db-2"] before the outer operation is applied.

Question 1126

For Terraform string processing with substring offsets, evaluate substr("deployment", 3, 4). Which output is correct?

  1. "ploy"
  2. "oyme"
  3. "depl"
  4. "loym"

Explanation

Correct Answer

D:

Evaluating the actual call substr("deployment", 3, 4): substr begins at zero-based index three, the l, and returns four characters: l, o, y, m.

Incorrect Answers

A:

Given the specific operands supplied to the Terraform expression substr("deployment", 3, 4), this starts before zero-based index three, which is the l position.

B:

Given the specific operands supplied to the Terraform expression substr("deployment", 3, 4), this starts one position late and so does not satisfy the offset argument.

C:

Given the specific operands supplied to the Terraform expression substr("deployment", 3, 4), this wrongly extracts the first four characters rather than beginning at offset three.

Question 1127

A Terraform 1.12 configuration evaluates format("primary=%s", element(formatlist("%s-%d", ["app", "db"], [1, 2]), 0)). Which result follows from the expression as written?

  1. "primary=db-2"
  2. "app-1"
  3. "secondary=app-1"
  4. "primary=app-1"

Explanation

Correct Answer

D:

For the specific expression format("primary=%s", element(formatlist("%s-%d", ["app", "db"], [1, 2]), 0)), First, formatlist formats the corresponding elements of both lists position by position; 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(formatlist("%s-%d", ["app", "db"], [1, 2]), 0)), this uses the second list element; element at index zero selects the first value; the inner stage produces ["app-1", "db-2"] before the outer operation is applied.

B:

For the concrete expression format("primary=%s", element(formatlist("%s-%d", ["app", "db"], [1, 2]), 0)), the format string has a literal primary= prefix that must appear in the result; the inner stage produces ["app-1", "db-2"] before the outer operation is applied.

C:

For the concrete expression format("primary=%s", element(formatlist("%s-%d", ["app", "db"], [1, 2]), 0)), the prefix is specified literally as primary= rather than secondary=; the inner stage produces ["app-1", "db-2"] before the outer operation is applied.

Question 1128

A Terraform 1.12 configuration evaluates length(coalescelist([], ["green", "blue"])). Which result follows from the expression as written?

  1. 2
  2. 0
  3. 1
  4. 5

Explanation

Correct Answer

A:

For the specific expression length(coalescelist([], ["green", "blue"])), First, coalescelist returns the first nonempty list, not merely its first element; that produces exactly 2 elements; The outer length call counts those resulting elements rather than the original textual arguments.

Incorrect Answers

B:

For the concrete expression length(coalescelist([], ["green", "blue"])), the inner expression is not empty: it produces 2 elements; the inner stage produces ["green", "blue"] before the outer operation is applied.

C:

For the concrete expression length(coalescelist([], ["green", "blue"])), there is more than one retained element after the inner calculation; the inner stage produces ["green", "blue"] before the outer operation is applied.

D:

For the concrete expression length(coalescelist([], ["green", "blue"])), no stage of the expression creates 5 list elements; the inner stage produces ["green", "blue"] before the outer operation is applied.

Question 1129

A Terraform 1.12 configuration evaluates join("/", coalescelist([], ["green", "blue"])). Which result follows from the expression as written?

  1. "green/blue/blue"
  2. "green/blue"
  3. "greenblue"
  4. "blue/green"

Explanation

Correct Answer

B:

For the specific expression join("/", coalescelist([], ["green", "blue"])), First, coalescelist returns the first nonempty list, not merely its first element; The outer join uses a slash only between consecutive list members and preserves their computed order.

Incorrect Answers

A:

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

C:

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

D:

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

Question 1130

A Terraform 1.12 configuration evaluates reverse(coalescelist([], ["green", "blue"])). Which result follows from the expression as written?

  1. ["blue"]
  2. []
  3. ["blue", "green"]
  4. ["green", "blue"]

Explanation

Correct Answer

C:

For the specific expression reverse(coalescelist([], ["green", "blue"])), First, coalescelist returns the first nonempty list, not merely its first element; reverse then returns the exact opposite element order, without sorting or removing members.

Incorrect Answers

A:

For the concrete expression reverse(coalescelist([], ["green", "blue"])), the reverse function does not discard an element of the input list; the inner stage produces ["green", "blue"] before the outer operation is applied.

B:

For the concrete expression reverse(coalescelist([], ["green", "blue"])), reversing a nonempty list does not create an empty list; the inner stage produces ["green", "blue"] before the outer operation is applied.

D:

For the concrete expression reverse(coalescelist([], ["green", "blue"])), this leaves the inner result unchanged and skips the outer reverse call; the inner stage produces ["green", "blue"] before the outer operation is applied.

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