Question 1130
A Terraform 1.12 configuration evaluates reverse(coalescelist([], ["green", "blue"])). Which result follows from the expression as written?
- ["blue"]
- []
- ["blue", "green"]
- ["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?
- ["green", "blue"]
- ["blue"]
- ["blue", "green", "green"]
- ["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?
- "blue"
- "green"
- "index out of range"
- 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?
- []
- ["blue"]
- ["green", "blue"]
- ["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?
- "green"
- "primary=green:extra"
- "primary=green"
- "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?
- 3
- 1
- 0
- 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?
- "DEV/PROD"
- "DEVPROD"
- "PROD/DEV"
- "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?
- []
- ["PROD", "DEV"]
- ["DEV", "PROD"]
- ["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)?
- "not-a-number"
- null
- 42
- 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?
- ["PROD", "DEV"]
- ["DEV"]
- []
- ["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?
- "spoduol"
- "cloudops"
- "spoduolc"
- "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.