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

Question 1090

A Terraform 1.12 configuration evaluates sort(flatten([["g1"], ["g2", "g3"]])). Which result follows from the expression as written?

  1. ["g1", "g2"]
  2. ["g2", "g3", "g1"]
  3. ["g1", "g2", "g3"]
  4. ["g3", "g2", "g1"]

Explanation

Correct Answer

C:

For the specific expression sort(flatten([["g1"], ["g2", "g3"]])), First, flatten removes nested list boundaries without changing member sequence; 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(flatten([["g1"], ["g2", "g3"]])), sorting does not remove the final element of the list; the inner stage produces ["g1", "g2", "g3"] before the outer operation is applied.

B:

For the concrete expression sort(flatten([["g1"], ["g2", "g3"]])), this rotates entries rather than sorting them lexicographically; the inner stage produces ["g1", "g2", "g3"] before the outer operation is applied.

D:

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

Question 1091

A Terraform 1.12 configuration evaluates element(flatten([["g1"], ["g2", "g3"]]), 4). Which result follows from the expression as written?

  1. "g1"
  2. "g3"
  3. "index out of range"
  4. "g2"

Explanation

Correct Answer

D:

For the specific expression element(flatten([["g1"], ["g2", "g3"]]), 4), First, flatten removes nested list boundaries without changing member sequence; 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(flatten([["g1"], ["g2", "g3"]]), 4), index wraparound lands at position one, not the first position of the inner list; the inner stage produces ["g1", "g2", "g3"] before the outer operation is applied.

B:

For the concrete expression element(flatten([["g1"], ["g2", "g3"]]), 4), the final list member is not selected; the effective index is one; the inner stage produces ["g1", "g2", "g3"] before the outer operation is applied.

C:

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

Question 1092

A Terraform 1.12 configuration evaluates slice(flatten([["g1"], ["g2", "g3"]]), 1, 3). Which result follows from the expression as written?

  1. ["g2", "g3"]
  2. ["g1", "g2", "g3"]
  3. ["g1", "g2"]
  4. ["g3", "g2"]

Explanation

Correct Answer

A:

For the specific expression slice(flatten([["g1"], ["g2", "g3"]]), 1, 3), First, flatten removes nested list boundaries without changing member sequence; slice begins at zero-based index one and continues through the final member, stopping before the exclusive end index 3.

Incorrect Answers

B:

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

C:

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

D:

For the concrete expression slice(flatten([["g1"], ["g2", "g3"]]), 1, 3), slice preserves order rather than reversing the extracted portion; the inner stage produces ["g1", "g2", "g3"] before the outer operation is applied.

Question 1093

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

  1. "secondary=g1"
  2. "primary=g1"
  3. "primary=g2"
  4. "g1"

Explanation

Correct Answer

B:

For the specific expression format("primary=%s", element(flatten([["g1"], ["g2", "g3"]]), 0)), First, flatten removes nested list boundaries without changing member sequence; 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(flatten([["g1"], ["g2", "g3"]]), 0)), the prefix is specified literally as primary= rather than secondary=; the inner stage produces ["g1", "g2", "g3"] before the outer operation is applied.

C:

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

D:

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

Question 1094

A Terraform 1.12 configuration evaluates length(slice(["a", "b", "c", "d"], 1, 4)). Which result follows from the expression as written?

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

Explanation

Correct Answer

C:

For the specific expression length(slice(["a", "b", "c", "d"], 1, 4)), First, slice includes the start index and excludes the end index; 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(slice(["a", "b", "c", "d"], 1, 4)), 5 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(slice(["a", "b", "c", "d"], 1, 4)), no stage of the expression creates 6 list elements; the inner stage produces ["b", "c", "d"] before the outer operation is applied.

D:

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

Question 1095

A Terraform 1.12 configuration evaluates join("/", slice(["a", "b", "c", "d"], 1, 4)). Which result follows from the expression as written?

  1. "bcd"
  2. "d/c/b"
  3. "b/c/d/d"
  4. "b/c/d"

Explanation

Correct Answer

D:

For the specific expression join("/", slice(["a", "b", "c", "d"], 1, 4)), First, slice includes the start index and excludes the end index; The outer join uses a slash only between consecutive list members and preserves their computed order.

Incorrect Answers

A:

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

B:

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

C:

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

Question 1096

An engineer tests the compact behavior in terraform console. What is the result of compact(["db", "", "api", ""])?

  1. ["db", "api"]
  2. ["db"]
  3. ["api", "db"]
  4. ["db", "", "api", ""] (with original input formatting 1)

Explanation

Correct Answer

A:

Evaluating the actual call compact(["db", "", "api", ""]): compact removes empty string elements and retains the nonempty strings db and api in their original order.

Incorrect Answers

B:

Given the specific operands supplied to the Terraform expression compact(["db", "", "api", ""]), the nonempty api member must remain alongside db.

C:

Given the specific operands supplied to the Terraform expression compact(["db", "", "api", ""]), the relative order of nonempty list members is unchanged by compact.

D:

Given the specific operands supplied to the Terraform expression compact(["db", "", "api", ""]), this retains the empty strings that compact is designed to discard.

Question 1097

A Terraform 1.12 configuration evaluates reverse(slice(["a", "b", "c", "d"], 1, 4)). Which result follows from the expression as written?

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

Explanation

Correct Answer

B:

For the specific expression reverse(slice(["a", "b", "c", "d"], 1, 4)), First, slice includes the start index and excludes the end index; reverse then returns the exact opposite element order, without sorting or removing members.

Incorrect Answers

A:

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

C:

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

D:

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

Question 1098

For Terraform string processing with prefix removal, evaluate trimprefix("prod-api", "prod-"). Which output is correct?

  1. "api-prod"
  2. "api"
  3. "prod-api"
  4. "prod"

Explanation

Correct Answer

B:

Evaluating the actual call trimprefix("prod-api", "prod-"): trimprefix removes the literal prod- prefix and preserves the rest of the string as api.

Incorrect Answers

A:

Given the specific operands supplied to the Terraform expression trimprefix("prod-api", "prod-"), the operation removes the prefix; it does not move the original prefix to the end.

C:

Given the specific operands supplied to the Terraform expression trimprefix("prod-api", "prod-"), this leaves the prefix in place even though it matches the supplied removal prefix.

D:

Given the specific operands supplied to the Terraform expression trimprefix("prod-api", "prod-"), the function preserves the remainder api rather than returning the prefix prod.

Question 1099

A Terraform 1.12 configuration evaluates sort(slice(["a", "b", "c", "d"], 1, 4)). Which result follows from the expression as written?

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

Explanation

Correct Answer

D:

For the specific expression sort(slice(["a", "b", "c", "d"], 1, 4)), First, slice includes the start index and excludes the end index; 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(slice(["a", "b", "c", "d"], 1, 4)), a reversal is not guaranteed to produce ascending lexical order; the inner stage produces ["b", "c", "d"] before the outer operation is applied.

B:

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

C:

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

Question 1100

A Terraform 1.12 configuration evaluates element(slice(["a", "b", "c", "d"], 1, 4), 4). Which result follows from the expression as written?

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

Explanation

Correct Answer

A:

For the specific expression element(slice(["a", "b", "c", "d"], 1, 4), 4), First, slice includes the start index and excludes the end index; 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(slice(["a", "b", "c", "d"], 1, 4), 4), index wraparound lands at position one, not the first position of the inner list; the inner stage produces ["b", "c", "d"] before the outer operation is applied.

C:

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

D:

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

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