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

Question 1150

A Terraform 1.12 configuration evaluates format("primary=%s", element(compact(split(",", "a,,b,c")), 0)). Which result follows from the expression as written?

  1. "a"
  2. "secondary=a"
  3. "primary=a"
  4. "primary=b"

Explanation

Correct Answer

C:

For the specific expression format("primary=%s", element(compact(split(",", "a,,b,c")), 0)), First, split creates an empty segment between consecutive commas and compact removes it; 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(compact(split(",", "a,,b,c")), 0)), the format string has a literal primary= prefix that must appear in the result; the inner stage produces ["a", "b", "c"] before the outer operation is applied.

B:

For the concrete expression format("primary=%s", element(compact(split(",", "a,,b,c")), 0)), the prefix is specified literally as primary= rather than secondary=; the inner stage produces ["a", "b", "c"] before the outer operation is applied.

D:

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

Question 1151

A Terraform 1.12 configuration evaluates length(sort(distinct(["q", "a", "q", "m"]))). Which result follows from the expression as written?

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

Explanation

Correct Answer

D:

For the specific expression length(sort(distinct(["q", "a", "q", "m"]))), First, distinct removes the repeated q, then sort orders the remaining strings; 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(sort(distinct(["q", "a", "q", "m"]))), 4 is not the size of the evaluated collection: the inner result has 3 elements, and length counts precisely those elements.

B:

For the concrete expression length(sort(distinct(["q", "a", "q", "m"]))), the inner expression is not empty: it produces 3 elements; the inner stage produces ["a", "m", "q"] before the outer operation is applied.

C:

For the concrete expression length(sort(distinct(["q", "a", "q", "m"]))), there is more than one retained element after the inner calculation; the inner stage produces ["a", "m", "q"] before the outer operation is applied.

Question 1152

An engineer tests the can behavior in terraform console. What is the result of can(tonumber("broken"))?

  1. true
  2. 0
  3. "broken"
  4. false

Explanation

Correct Answer

D:

Evaluating the actual call can(tonumber("broken")): can tests whether the attempted expression can evaluate without error; tonumber cannot parse broken, producing false.

Incorrect Answers

A:

Given the specific operands supplied to the Terraform expression can(tonumber("broken")), the conversion would error, so can does not return true.

B:

Given the specific operands supplied to the Terraform expression can(tonumber("broken")), can returns a boolean, not a zero numeric fallback.

C:

Given the specific operands supplied to the Terraform expression can(tonumber("broken")), the original string is not a return value of can; it tests evaluation success.

Question 1153

A Terraform 1.12 configuration evaluates join("/", sort(distinct(["q", "a", "q", "m"]))). Which result follows from the expression as written?

  1. "a/m/q/q"
  2. "a/m/q"
  3. "amq"
  4. "q/m/a"

Explanation

Correct Answer

B:

For the specific expression join("/", sort(distinct(["q", "a", "q", "m"]))), First, distinct removes the repeated q, then sort orders the remaining strings; The outer join uses a slash only between consecutive list members and preserves their computed order.

Incorrect Answers

A:

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

C:

For the concrete expression join("/", sort(distinct(["q", "a", "q", "m"]))), this omits the slash delimiters requested by join; the inner stage produces ["a", "m", "q"] before the outer operation is applied.

D:

For the concrete expression join("/", sort(distinct(["q", "a", "q", "m"]))), this reverses the members even though join preserves the order returned by the inner expression; the inner stage produces ["a", "m", "q"] before the outer operation is applied.

Question 1154

For Terraform string processing with join path components, evaluate join("/", ["dev", "api", "logs"]). Which output is correct?

  1. "dev/api/logs"
  2. "dev-logs-api"
  3. "dev/api/logs/" (with original input formatting 2)
  4. "dev,api,logs" (with original input formatting 1)

Explanation

Correct Answer

A:

Evaluating the actual call join("/", ["dev", "api", "logs"]): join inserts / between consecutive list values without adding a trailing delimiter, retaining dev, api, logs order.

Incorrect Answers

B:

Given the specific operands supplied to the Terraform expression join("/", ["dev", "api", "logs"]), this changes the specified separator and member order, neither of which join does.

C:

Given the specific operands supplied to the Terraform expression join("/", ["dev", "api", "logs"]), join inserts separators between items; it does not append a trailing slash.

D:

Given the specific operands supplied to the Terraform expression join("/", ["dev", "api", "logs"]), the delimiter is explicitly slash rather than a comma.

Question 1155

A Terraform 1.12 configuration evaluates reverse(sort(distinct(["q", "a", "q", "m"]))). Which result follows from the expression as written?

  1. ["a", "m", "q"]
  2. ["m", "q", "a"]
  3. ["m", "a", "q"]
  4. ["q", "m", "a"]

Explanation

Correct Answer

D:

For the specific expression reverse(sort(distinct(["q", "a", "q", "m"]))), First, distinct removes the repeated q, then sort orders the remaining strings; reverse then returns the exact opposite element order, without sorting or removing members.

Incorrect Answers

A:

For the concrete expression reverse(sort(distinct(["q", "a", "q", "m"]))), this leaves the inner result unchanged and skips the outer reverse call; the inner stage produces ["a", "m", "q"] before the outer operation is applied.

B:

For the concrete expression reverse(sort(distinct(["q", "a", "q", "m"]))), rotating the input left one position does not invert every position as reverse requires; the inner stage produces ["a", "m", "q"] before the outer operation is applied.

C:

For the concrete expression reverse(sort(distinct(["q", "a", "q", "m"]))), this rotates the reversed list rather than returning the exact reversed sequence; the inner stage produces ["a", "m", "q"] before the outer operation is applied.

Question 1156

A Terraform 1.12 configuration evaluates sort(sort(distinct(["q", "a", "q", "m"]))). Which result follows from the expression as written?

  1. ["a", "m", "q"]
  2. ["q", "m", "a"]
  3. ["a", "m"]
  4. ["m", "q", "a"]

Explanation

Correct Answer

A:

For the specific expression sort(sort(distinct(["q", "a", "q", "m"]))), First, distinct removes the repeated q, then sort orders the remaining strings; Terraform sort then compares the resulting strings lexicographically in ascending order; it neither drops values nor preserves a non-sorted arrangement.

Incorrect Answers

B:

For the concrete expression sort(sort(distinct(["q", "a", "q", "m"]))), a reversal is not guaranteed to produce ascending lexical order; the inner stage produces ["a", "m", "q"] before the outer operation is applied.

C:

For the concrete expression sort(sort(distinct(["q", "a", "q", "m"]))), sorting does not remove the final element of the list; the inner stage produces ["a", "m", "q"] before the outer operation is applied.

D:

For the concrete expression sort(sort(distinct(["q", "a", "q", "m"]))), this rotates entries rather than sorting them lexicographically; the inner stage produces ["a", "m", "q"] before the outer operation is applied.

Question 1157

A Terraform 1.12 configuration evaluates element(sort(distinct(["q", "a", "q", "m"])), 4). Which result follows from the expression as written?

  1. "index out of range"
  2. "m"
  3. "a"
  4. "q"

Explanation

Correct Answer

B:

For the specific expression element(sort(distinct(["q", "a", "q", "m"])), 4), First, distinct removes the repeated q, then sort orders the remaining strings; The list has 3 entries, so element wraps index 4 modulo 3 and selects zero-based position one.

Incorrect Answers

A:

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

C:

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

D:

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

Question 1158

A Terraform 1.12 configuration evaluates slice(sort(distinct(["q", "a", "q", "m"])), 1, 3). Which result follows from the expression as written?

  1. ["a", "m"]
  2. ["q", "m"]
  3. ["m", "q"]
  4. ["a", "m", "q"]

Explanation

Correct Answer

C:

For the specific expression slice(sort(distinct(["q", "a", "q", "m"])), 1, 3), First, distinct removes the repeated q, then sort orders the remaining strings; 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(sort(distinct(["q", "a", "q", "m"])), 1, 3), this takes an initial prefix rather than starting with the second entry; the inner stage produces ["a", "m", "q"] before the outer operation is applied.

B:

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

D:

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

Question 1159

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

  1. "primary=m"
  2. "a"
  3. "primary=a:extra"
  4. "primary=a"

Explanation

Correct Answer

D:

For the specific expression format("primary=%s", element(sort(distinct(["q", "a", "q", "m"])), 0)), First, distinct removes the repeated q, then sort orders the remaining strings; 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(sort(distinct(["q", "a", "q", "m"])), 0)), this uses the second list element; element at index zero selects the first value; the inner stage produces ["a", "m", "q"] before the outer operation is applied.

B:

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

C:

The extra text is not generated by format("primary=%s", element(sort(distinct(["q", "a", "q", "m"])), 0)), because the final operation substitutes only the literal list members and format placeholders that are actually present.

Question 1160

A Terraform 1.12 configuration evaluates length(split(":", "auth:read:write")). Which result follows from the expression as written?

  1. 3
  2. 5
  3. 1
  4. 6

Explanation

Correct Answer

A:

For the specific expression length(split(":", "auth:read:write")), First, split separates the three colon-delimited fields in input order; that produces exactly 3 elements; The outer length call counts those resulting elements rather than the original textual arguments.

Incorrect Answers

B:

In the calculation length(split(":", "auth:read:write")), 5 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(split(":", "auth:read:write")), there is more than one retained element after the inner calculation; the inner stage produces ["auth", "read", "write"] before the outer operation is applied.

D:

For the concrete expression length(split(":", "auth:read:write")), no stage of the expression creates 6 list elements; the inner stage produces ["auth", "read", "write"] before the outer operation is applied.

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