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

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.

Question 1131

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

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

Explanation

Correct Answer

D:

For the specific expression sort(coalescelist([], ["green", "blue"])), First, coalescelist returns the first nonempty list, not merely its first element; 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(coalescelist([], ["green", "blue"])), this retains the source order rather than explicitly sorting the result (unless it was already sorted); the inner stage produces ["green", "blue"] before the outer operation is applied.

B:

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

C:

The alternative changes the member count or order by injecting or dropping an entry; the particular expression sort(coalescelist([], ["green", "blue"])) neither makes that extra insertion nor drops the required entry.

Question 1132

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

  1. "blue"
  2. "green"
  3. "index out of range"
  4. null

Explanation

Correct Answer

A:

For the specific expression element(coalescelist([], ["green", "blue"]), 3), First, coalescelist returns the first nonempty list, not merely its first element; The list has 2 entries, so element wraps index 3 modulo 2 and selects zero-based position one.

Incorrect Answers

B:

For the concrete expression element(coalescelist([], ["green", "blue"]), 3), index wraparound lands at position one, not the first position of the inner list; the inner stage produces ["green", "blue"] before the outer operation is applied.

C:

For the concrete expression element(coalescelist([], ["green", "blue"]), 3), element wraps a positive index instead of failing like ordinary square-bracket indexing; the inner stage produces ["green", "blue"] before the outer operation is applied.

D:

For the concrete expression element(coalescelist([], ["green", "blue"]), 3), element returns a known string from this nonempty computed list, not a null result; the inner stage produces ["green", "blue"] before the outer operation is applied.

Question 1133

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

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

Explanation

Correct Answer

B:

For the specific expression slice(coalescelist([], ["green", "blue"]), 1, 2), First, coalescelist returns the first nonempty list, not merely its first element; 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(coalescelist([], ["green", "blue"]), 1, 2), the final end index is exclusive, but the last element still lies before that boundary; the inner stage produces ["green", "blue"] before the outer operation is applied.

C:

For the concrete expression slice(coalescelist([], ["green", "blue"]), 1, 2), this incorrectly keeps the first list member, although the slice begins at index one; the inner stage produces ["green", "blue"] before the outer operation is applied.

D:

For the concrete expression slice(coalescelist([], ["green", "blue"]), 1, 2), this takes an initial prefix rather than starting with the second entry; the inner stage produces ["green", "blue"] before the outer operation is applied.

Question 1134

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

  1. "green"
  2. "primary=green:extra"
  3. "primary=green"
  4. "primary=blue"

Explanation

Correct Answer

C:

For the specific expression format("primary=%s", element(coalescelist([], ["green", "blue"]), 0)), First, coalescelist returns the first nonempty list, not merely its first element; 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(coalescelist([], ["green", "blue"]), 0)), the format string has a literal primary= prefix that must appear in the result; the inner stage produces ["green", "blue"] before the outer operation is applied.

B:

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

D:

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

Question 1135

A Terraform 1.12 configuration evaluates length([for s in ["dev", "prod"] : upper(s)]). Which result follows from the expression as written?

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

Explanation

Correct Answer

D:

For the specific expression length([for s in ["dev", "prod"] : upper(s)]), First, the for expression uppercases each input string in order; that produces exactly 2 elements; The outer length call counts those resulting elements rather than the original textual arguments.

Incorrect Answers

A:

For the concrete expression length([for s in ["dev", "prod"] : upper(s)]), this counts one element beyond the 2 values produced by the inner expression; the inner stage produces ["DEV", "PROD"] before the outer operation is applied.

B:

For the concrete expression length([for s in ["dev", "prod"] : upper(s)]), this drops one legitimate list element; the inner operation returns 2 values; the inner stage produces ["DEV", "PROD"] before the outer operation is applied.

C:

In the calculation length([for s in ["dev", "prod"] : upper(s)]), 0 is not the size of the evaluated collection: the inner result has 2 elements, and length counts precisely those elements.

Question 1136

A Terraform 1.12 configuration evaluates join("/", [for s in ["dev", "prod"] : upper(s)]). Which result follows from the expression as written?

  1. "DEV/PROD"
  2. "DEVPROD"
  3. "PROD/DEV"
  4. "DEV/PROD/PROD"

Explanation

Correct Answer

A:

For the specific expression join("/", [for s in ["dev", "prod"] : upper(s)]), First, the for expression uppercases each input string in order; The outer join uses a slash only between consecutive list members and preserves their computed order.

Incorrect Answers

B:

For the concrete expression join("/", [for s in ["dev", "prod"] : upper(s)]), this omits the slash delimiters requested by join; the inner stage produces ["DEV", "PROD"] before the outer operation is applied.

C:

For the concrete expression join("/", [for s in ["dev", "prod"] : upper(s)]), this reverses the members even though join preserves the order returned by the inner expression; the inner stage produces ["DEV", "PROD"] before the outer operation is applied.

D:

For the concrete expression join("/", [for s in ["dev", "prod"] : upper(s)]), join must not repeat the last item after the list has been joined; the inner stage produces ["DEV", "PROD"] before the outer operation is applied.

Question 1137

A Terraform 1.12 configuration evaluates reverse([for s in ["dev", "prod"] : upper(s)]). Which result follows from the expression as written?

  1. []
  2. ["PROD", "DEV"]
  3. ["DEV", "PROD"]
  4. ["PROD"]

Explanation

Correct Answer

B:

For the specific expression reverse([for s in ["dev", "prod"] : upper(s)]), First, the for expression uppercases each input string in order; reverse then returns the exact opposite element order, without sorting or removing members.

Incorrect Answers

A:

For the concrete expression reverse([for s in ["dev", "prod"] : upper(s)]), reversing a nonempty list does not create an empty list; the inner stage produces ["DEV", "PROD"] before the outer operation is applied.

C:

For the concrete expression reverse([for s in ["dev", "prod"] : upper(s)]), this leaves the inner result unchanged and skips the outer reverse call; the inner stage produces ["DEV", "PROD"] before the outer operation is applied.

D:

For the concrete expression reverse([for s in ["dev", "prod"] : upper(s)]), the reverse function does not discard an element of the input list; the inner stage produces ["DEV", "PROD"] before the outer operation is applied.

Question 1138

An engineer tests the try behavior in terraform console. What is the result of try(tonumber("not-a-number"), 42)?

  1. "not-a-number"
  2. null
  3. 42
  4. 0

Explanation

Correct Answer

C:

Evaluating the actual call try(tonumber("not-a-number"), 42): tonumber raises a dynamic conversion error for this string; try catches it and returns the numeric fallback 42.

Incorrect Answers

A:

Given the specific operands supplied to the Terraform expression try(tonumber("not-a-number"), 42), try returns the fallback value after conversion fails, not the invalid input string.

B:

Given the specific operands supplied to the Terraform expression try(tonumber("not-a-number"), 42), the second argument supplies a valid number; try uses it instead of returning null.

D:

Given the specific operands supplied to the Terraform expression try(tonumber("not-a-number"), 42), no numeric zero is provided as a fallback, and the string cannot be converted.

Question 1139

A Terraform 1.12 configuration evaluates sort([for s in ["dev", "prod"] : upper(s)]). Which result follows from the expression as written?

  1. ["PROD", "DEV"]
  2. ["DEV"]
  3. []
  4. ["DEV", "PROD"]

Explanation

Correct Answer

D:

For the specific expression sort([for s in ["dev", "prod"] : upper(s)]), First, the for expression uppercases each input string in order; 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([for s in ["dev", "prod"] : upper(s)]), a reversal is not guaranteed to produce ascending lexical order; the inner stage produces ["DEV", "PROD"] before the outer operation is applied.

B:

For the concrete expression sort([for s in ["dev", "prod"] : upper(s)]), sorting does not remove the final element of the list; the inner stage produces ["DEV", "PROD"] before the outer operation is applied.

C:

For the concrete expression sort([for s in ["dev", "prod"] : upper(s)]), the outer sort does not empty the nonempty collection; the inner stage produces ["DEV", "PROD"] before the outer operation is applied.

Question 1140

For Terraform string processing with reverse characters, evaluate strrev("cloudops"). Which output is correct?

  1. "spoduol"
  2. "cloudops"
  3. "spoduolc"
  4. "opscloud"

Explanation

Correct Answer

C:

Evaluating the actual call strrev("cloudops"): strrev reverses the characters of cloudops, moving the final s to the front and the initial c to the end.

Incorrect Answers

A:

Given the specific operands supplied to the Terraform expression strrev("cloudops"), the original c remains a character and must appear at the very end of the reversed result.

B:

Given the specific operands supplied to the Terraform expression strrev("cloudops"), this preserves the source string and ignores the reversal operation.

D:

Given the specific operands supplied to the Terraform expression strrev("cloudops"), this swaps two apparent parts rather than reversing every individual character.

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