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

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.

Question 1141

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

  1. null
  2. "PROD"
  3. "DEV"
  4. "index out of range"

Explanation

Correct Answer

B:

For the specific expression element([for s in ["dev", "prod"] : upper(s)], 3), First, the for expression uppercases each input string in order; 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([for s in ["dev", "prod"] : upper(s)], 3), element returns a known string from this nonempty computed list, not a null result; the inner stage produces ["DEV", "PROD"] before the outer operation is applied.

C:

For the concrete expression element([for s in ["dev", "prod"] : upper(s)], 3), index wraparound lands at position one, not the first position of the inner list; the inner stage produces ["DEV", "PROD"] before the outer operation is applied.

D:

For the concrete expression element([for s in ["dev", "prod"] : upper(s)], 3), element wraps a positive index instead of failing like ordinary square-bracket indexing; the inner stage produces ["DEV", "PROD"] before the outer operation is applied.

Question 1142

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

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

Explanation

Correct Answer

C:

For the specific expression slice([for s in ["dev", "prod"] : upper(s)], 1, 2), First, the for expression uppercases each input string in order; 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([for s in ["dev", "prod"] : upper(s)], 1, 2), this takes an initial prefix rather than starting with the second entry; the inner stage produces ["DEV", "PROD"] before the outer operation is applied.

B:

For the concrete expression slice([for s in ["dev", "prod"] : upper(s)], 1, 2), the final end index is exclusive, but the last element still lies before that boundary; the inner stage produces ["DEV", "PROD"] before the outer operation is applied.

D:

For the concrete expression slice([for s in ["dev", "prod"] : upper(s)], 1, 2), this incorrectly keeps the first list member, although the slice begins at index one; the inner stage produces ["DEV", "PROD"] before the outer operation is applied.

Question 1143

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

  1. "primary=PROD"
  2. "DEV"
  3. "primary=DEV:extra"
  4. "primary=DEV"

Explanation

Correct Answer

D:

For the specific expression format("primary=%s", element([for s in ["dev", "prod"] : upper(s)], 0)), First, the for expression uppercases each input string in order; 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([for s in ["dev", "prod"] : upper(s)], 0)), this uses the second list element; element at index zero selects the first value; the inner stage produces ["DEV", "PROD"] before the outer operation is applied.

B:

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

C:

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

Question 1144

A Terraform 1.12 configuration evaluates length(compact(split(",", "a,,b,c"))). Which result follows from the expression as written?

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

Explanation

Correct Answer

A:

For the specific expression length(compact(split(",", "a,,b,c"))), First, split creates an empty segment between consecutive commas and compact removes it; that produces exactly 3 elements; The outer length call counts those resulting elements rather than the original textual arguments.

Incorrect Answers

B:

For the concrete expression length(compact(split(",", "a,,b,c"))), this drops one legitimate list element; the inner operation returns 3 values; the inner stage produces ["a", "b", "c"] before the outer operation is applied.

C:

In the calculation length(compact(split(",", "a,,b,c"))), 6 is not the size of the evaluated collection: the inner result has 3 elements, and length counts precisely those elements.

D:

For the concrete expression length(compact(split(",", "a,,b,c"))), the inner expression is not empty: it produces 3 elements; the inner stage produces ["a", "b", "c"] before the outer operation is applied.

Question 1145

A Terraform 1.12 configuration evaluates join("/", compact(split(",", "a,,b,c"))). Which result follows from the expression as written?

  1. "a/b/c/c"
  2. "a/b/c"
  3. "abc"
  4. "c/b/a"

Explanation

Correct Answer

B:

For the specific expression join("/", compact(split(",", "a,,b,c"))), First, split creates an empty segment between consecutive commas and compact removes it; The outer join uses a slash only between consecutive list members and preserves their computed order.

Incorrect Answers

A:

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

C:

For the concrete expression join("/", compact(split(",", "a,,b,c"))), this omits the slash delimiters requested by join; the inner stage produces ["a", "b", "c"] before the outer operation is applied.

D:

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

Question 1146

A Terraform 1.12 configuration evaluates reverse(compact(split(",", "a,,b,c"))). Which result follows from the expression as written?

  1. ["b", "c", "a"]
  2. ["b", "a", "c"]
  3. ["c", "b", "a"]
  4. ["a", "b", "c"]

Explanation

Correct Answer

C:

For the specific expression reverse(compact(split(",", "a,,b,c"))), First, split creates an empty segment between consecutive commas and compact removes it; reverse then returns the exact opposite element order, without sorting or removing members.

Incorrect Answers

A:

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

B:

For the concrete expression reverse(compact(split(",", "a,,b,c"))), this rotates the reversed list rather than returning the exact reversed sequence; the inner stage produces ["a", "b", "c"] before the outer operation is applied.

D:

For the concrete expression reverse(compact(split(",", "a,,b,c"))), this leaves the inner result unchanged and skips the outer reverse call; the inner stage produces ["a", "b", "c"] before the outer operation is applied.

Question 1147

A Terraform 1.12 configuration evaluates sort(compact(split(",", "a,,b,c"))). Which result follows from the expression as written?

  1. ["c", "b", "a"]
  2. ["a", "b"]
  3. ["b", "c", "a"]
  4. ["a", "b", "c"]

Explanation

Correct Answer

D:

For the specific expression sort(compact(split(",", "a,,b,c"))), First, split creates an empty segment between consecutive commas and compact removes it; 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(compact(split(",", "a,,b,c"))), a reversal is not guaranteed to produce ascending lexical order; the inner stage produces ["a", "b", "c"] before the outer operation is applied.

B:

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

C:

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

Question 1148

A Terraform 1.12 configuration evaluates element(compact(split(",", "a,,b,c")), 4). Which result follows from the expression as written?

  1. "b"
  2. "a"
  3. "c"
  4. "index out of range"

Explanation

Correct Answer

A:

For the specific expression element(compact(split(",", "a,,b,c")), 4), First, split creates an empty segment between consecutive commas and compact removes it; 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(compact(split(",", "a,,b,c")), 4), index wraparound lands at position one, not the first position of the inner list; the inner stage produces ["a", "b", "c"] before the outer operation is applied.

C:

For the concrete expression element(compact(split(",", "a,,b,c")), 4), the final list member is not selected; the effective index is one; the inner stage produces ["a", "b", "c"] before the outer operation is applied.

D:

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

Question 1149

A Terraform 1.12 configuration evaluates slice(compact(split(",", "a,,b,c")), 1, 3). Which result follows from the expression as written?

  1. ["c", "b"]
  2. ["b", "c"]
  3. ["a", "b", "c"]
  4. ["a", "b"]

Explanation

Correct Answer

B:

For the specific expression slice(compact(split(",", "a,,b,c")), 1, 3), First, split creates an empty segment between consecutive commas and compact removes it; 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(compact(split(",", "a,,b,c")), 1, 3), slice preserves order rather than reversing the extracted portion; the inner stage produces ["a", "b", "c"] before the outer operation is applied.

C:

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

D:

For the concrete expression slice(compact(split(",", "a,,b,c")), 1, 3), this takes an initial prefix rather than starting with the second entry; the inner stage produces ["a", "b", "c"] before the outer operation is applied.

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.

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