Question 1030
A Terraform 1.12 configuration evaluates sort(compact(["api", "", "edge", ""])). Which result follows from the expression as written?
- ["api"]
- []
- ["api", "edge"]
- ["edge", "api"]
Explanation
Correct Answer
C:For the specific expression sort(compact(["api", "", "edge", ""])), First, compact eliminates empty strings but retains the nonempty input 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(compact(["api", "", "edge", ""])), sorting does not remove the final element of the list; the inner stage produces ["api", "edge"] before the outer operation is applied.
B:For the concrete expression sort(compact(["api", "", "edge", ""])), the outer sort does not empty the nonempty collection; the inner stage produces ["api", "edge"] before the outer operation is applied.
D:For the concrete expression sort(compact(["api", "", "edge", ""])), a reversal is not guaranteed to produce ascending lexical order; the inner stage produces ["api", "edge"] before the outer operation is applied.
Question 1031
During an implementation review, a Terraform team encounters "terraform fmt -diff". Which purpose is associated with that mechanism?
- fail a style gate without modifying source files
- rewrite Terraform configuration into its canonical layout
- make formatting a pre-merge quality gate
- display differences that canonical formatting would introduce
Explanation
Correct Answer
D:The practical result of terraform fmt -diff, used to display differences that canonical formatting would introduce, is: terraform fmt -diff shows a style diff for files that need formatting. A qualification for this effect is: A style diff is not an infrastructure change plan.
Incorrect Answers
A:That outcome applies to terraform fmt -check, intended to fail a style gate without modifying source files, rather than the question's feature terraform fmt -diff: terraform fmt -check tests whether files are already formatted and returns an exit status. Unlike terraform fmt -check, terraform fmt -diff is intended to display differences that canonical formatting would introduce, not to fail a style gate without modifying source files.
B:That outcome applies to terraform fmt command, intended to rewrite Terraform configuration into its canonical layout, rather than the question's feature terraform fmt -diff: terraform fmt formats Terraform language files consistently, including spacing and alignment. Unlike terraform fmt command, terraform fmt -diff is intended to display differences that canonical formatting would introduce, not to rewrite Terraform configuration into its canonical layout.
C:The outcome in this option belongs to HCL style consistency in CI: A pipeline can run fmt -check before validate and plan to enforce consistent source layout; by contrast, the feature actually named in the stem, terraform fmt -diff, has a distinct purpose: to display differences that canonical formatting would introduce.
Question 1032
A Terraform 1.12 configuration evaluates element(compact(["api", "", "edge", ""]), 3). Which result follows from the expression as written?
- "edge"
- "api"
- "index out of range"
- null
Explanation
Correct Answer
A:For the specific expression element(compact(["api", "", "edge", ""]), 3), First, compact eliminates empty strings but retains the nonempty input order; 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(compact(["api", "", "edge", ""]), 3), index wraparound lands at position one, not the first position of the inner list; the inner stage produces ["api", "edge"] before the outer operation is applied.
C:For the concrete expression element(compact(["api", "", "edge", ""]), 3), element wraps a positive index instead of failing like ordinary square-bracket indexing; the inner stage produces ["api", "edge"] before the outer operation is applied.
D:For the concrete expression element(compact(["api", "", "edge", ""]), 3), element returns a known string from this nonempty computed list, not a null result; the inner stage produces ["api", "edge"] before the outer operation is applied.
Question 1033
The rollout owner asks whether terraform fmt -diff is sufficient to display differences that canonical formatting would introduce. Which limitation specifically concerns that mechanism?
- A style diff is not an infrastructure change plan.
- It does not fetch remote modules to reformat their source repositories.
- Formatting does not validate external credentials or apply changes.
- Style compliance alone cannot prove semantic correctness.
Explanation
Correct Answer
A:For terraform fmt -diff in the task to display differences that canonical formatting would introduce, the important caution is: A style diff is not an infrastructure change plan. The reason this matters is its actual behavior: terraform fmt -diff shows a style diff for files that need formatting.
Incorrect Answers
B:The proposed warning belongs to terraform fmt -recursive, which serves the different goal to format Terraform configurations in nested local directories, rather than to terraform fmt -diff: The recursive flag expands formatting beyond just the current directory. The question concerns terraform fmt -diff acting to display differences that canonical formatting would introduce, not a limit of terraform fmt -recursive.
C:The proposed warning belongs to terraform fmt command, which serves the different goal to rewrite Terraform configuration into its canonical layout, rather than to terraform fmt -diff: terraform fmt formats Terraform language files consistently, including spacing and alignment. The question concerns terraform fmt -diff acting to display differences that canonical formatting would introduce, not a limit of terraform fmt command.
D:The listed caution belongs specifically to HCL style consistency in CI, used to make formatting a pre-merge quality gate: A pipeline can run fmt -check before validate and plan to enforce consistent source layout; the feature under review is instead terraform fmt -diff, so this answer attaches another feature's qualification to the wrong mechanism.
Question 1034
A Terraform 1.12 configuration evaluates slice(compact(["api", "", "edge", ""]), 1, 2). Which result follows from the expression as written?
- ["api"]
- []
- ["edge"]
- ["api", "edge"]
Explanation
Correct Answer
C:For the specific expression slice(compact(["api", "", "edge", ""]), 1, 2), First, compact eliminates empty strings but retains the nonempty input 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(compact(["api", "", "edge", ""]), 1, 2), this takes an initial prefix rather than starting with the second entry; the inner stage produces ["api", "edge"] before the outer operation is applied.
B:For the concrete expression slice(compact(["api", "", "edge", ""]), 1, 2), the final end index is exclusive, but the last element still lies before that boundary; the inner stage produces ["api", "edge"] before the outer operation is applied.
D:For the concrete expression slice(compact(["api", "", "edge", ""]), 1, 2), this incorrectly keeps the first list member, although the slice begins at index one; the inner stage produces ["api", "edge"] before the outer operation is applied.
Question 1035
A Terraform 1.12 configuration evaluates format("primary=%s", element(compact(["api", "", "edge", ""]), 0)). Which result follows from the expression as written?
- "primary=edge"
- "api"
- "secondary=api"
- "primary=api"
Explanation
Correct Answer
D:For the specific expression format("primary=%s", element(compact(["api", "", "edge", ""]), 0)), First, compact eliminates empty strings but retains the nonempty input 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(compact(["api", "", "edge", ""]), 0)), this uses the second list element; element at index zero selects the first value; the inner stage produces ["api", "edge"] before the outer operation is applied.
B:For the concrete expression format("primary=%s", element(compact(["api", "", "edge", ""]), 0)), the format string has a literal primary= prefix that must appear in the result; the inner stage produces ["api", "edge"] before the outer operation is applied.
C:For the concrete expression format("primary=%s", element(compact(["api", "", "edge", ""]), 0)), the prefix is specified literally as primary= rather than secondary=; the inner stage produces ["api", "edge"] before the outer operation is applied.
Question 1036
A Terraform rollout has two separate requirements: first, display differences that canonical formatting would introduce; second, make formatting a pre-merge quality gate. Which assignment of mechanisms correctly handles both responsibilities?
- First use terraform fmt -diff; then use Formatting and code review noise.
- First use terraform fmt -diff; then use HCL style consistency in CI.
- First use Formatting and code review noise; then use Formatting preserved semantics.
- First use Formatting preserved semantics; then use HCL style consistency in CI.
- First use HCL style consistency in CI; then use terraform fmt -diff.
Explanation
Correct Answer
B:The first requirement, to display differences that canonical formatting would introduce, is handled by terraform fmt -diff: terraform fmt -diff shows a style diff for files that need formatting. The second requirement, to make formatting a pre-merge quality gate, is handled by HCL style consistency in CI: A pipeline can run fmt -check before validate and plan to enforce consistent source layout. Each of these mechanisms has a distinct responsibility.
Incorrect Answers
A:For the requested tasks to display differences that canonical formatting would introduce and make formatting a pre-merge quality gate, the first candidate terraform fmt -diff addresses display differences that canonical formatting would introduce; the second candidate Formatting and code review noise addresses reduce insignificant whitespace changes across developers. This mapping fails because the second mechanism primarily supports the task to reduce insignificant whitespace changes across developers; the actual requirements are display differences that canonical formatting would introduce first and make formatting a pre-merge quality gate second.
C:For the requested tasks to display differences that canonical formatting would introduce and make formatting a pre-merge quality gate, the first candidate Formatting and code review noise addresses reduce insignificant whitespace changes across developers; the second candidate Formatting preserved semantics addresses change whitespace and presentation without intending resource changes. This mapping fails because the first mechanism primarily supports the task to reduce insignificant whitespace changes across developers and the second mechanism primarily supports the task to change whitespace and presentation without intending resource changes; the actual requirements are display differences that canonical formatting would introduce first and make formatting a pre-merge quality gate second.
D:For the requested tasks to display differences that canonical formatting would introduce and make formatting a pre-merge quality gate, the first candidate Formatting preserved semantics addresses change whitespace and presentation without intending resource changes; the second candidate HCL style consistency in CI addresses make formatting a pre-merge quality gate. This mapping fails because the first mechanism primarily supports the task to change whitespace and presentation without intending resource changes; the actual requirements are display differences that canonical formatting would introduce first and make formatting a pre-merge quality gate second.
E:For the requested tasks to display differences that canonical formatting would introduce and make formatting a pre-merge quality gate, the first candidate HCL style consistency in CI addresses make formatting a pre-merge quality gate; the second candidate terraform fmt -diff addresses display differences that canonical formatting would introduce. This mapping fails because the first mechanism primarily supports the task to make formatting a pre-merge quality gate and the second mechanism primarily supports the task to display differences that canonical formatting would introduce; the actual requirements are display differences that canonical formatting would introduce first and make formatting a pre-merge quality gate second.
Question 1037
A Terraform 1.12 configuration evaluates length(reverse(["red", "blue", "green"])). Which result follows from the expression as written?
- 1
- 3
- 5
- 0
Explanation
Correct Answer
B:For the specific expression length(reverse(["red", "blue", "green"])), First, reverse inverts list element order; that produces exactly 3 elements; The outer length call counts those resulting elements rather than the original textual arguments.
Incorrect Answers
A:For the concrete expression length(reverse(["red", "blue", "green"])), there is more than one retained element after the inner calculation; the inner stage produces ["green", "blue", "red"] before the outer operation is applied.
C:For the concrete expression length(reverse(["red", "blue", "green"])), the inner collection has 3 values, not 5; length counts the resulting collection only; the inner stage produces ["green", "blue", "red"] before the outer operation is applied.
D:For the concrete expression length(reverse(["red", "blue", "green"])), the inner expression is not empty: it produces 3 elements; the inner stage produces ["green", "blue", "red"] before the outer operation is applied.
Question 1038
The deployment owner requests a reliable way to format Terraform configurations in nested local directories. Which mechanism most directly meets this particular need?
- Formatting preserved semantics
- Formatting and code review noise
- terraform fmt command
- HCL style consistency in CI
- terraform fmt -recursive
Explanation
Correct Answer
E:The task is to format Terraform configurations in nested local directories; terraform fmt -recursive directly supports that requirement: The recursive flag expands formatting beyond just the current directory. Its relevant boundary is: It does not fetch remote modules to reformat their source repositories.
Incorrect Answers
A:Formatting preserved semantics is designed to change whitespace and presentation without intending resource changes, whereas this task is to format Terraform configurations in nested local directories: terraform fmt standardizes language presentation instead of performing infrastructure reconciliation. Against terraform fmt -recursive, its limitation is: Operators should still review unexpected source diffs from any automated formatter.
B:Formatting and code review noise is designed to reduce insignificant whitespace changes across developers, whereas this task is to format Terraform configurations in nested local directories: Canonical formatting minimizes differences due solely to manual layout preferences. Against terraform fmt -recursive, its limitation is: A formatted file can still describe unsafe infrastructure operations.
C:terraform fmt command is designed to rewrite Terraform configuration into its canonical layout, whereas this task is to format Terraform configurations in nested local directories: terraform fmt formats Terraform language files consistently, including spacing and alignment. Against terraform fmt -recursive, its limitation is: Formatting does not validate external credentials or apply changes.
D:HCL style consistency in CI is designed to make formatting a pre-merge quality gate, whereas this task is to format Terraform configurations in nested local directories: A pipeline can run fmt -check before validate and plan to enforce consistent source layout. Against terraform fmt -recursive, its limitation is: Style compliance alone cannot prove semantic correctness.
Question 1039
An engineer tests the range behavior in terraform console. What is the result of range(2, 11, 3)?
- [2, 5, 8]
- [2, 3, 4]
- [2, 5, 8, 10]
- [2, 5, 8, 11]
Explanation
Correct Answer
A:Evaluating the actual call range(2, 11, 3): range starts at two, advances in steps of three, and excludes the endpoint eleven, yielding 2, 5 and 8.
Incorrect Answers
B:Given the specific operands supplied to the Terraform expression range(2, 11, 3), the step value is three rather than one, so consecutive integers are not emitted.
C:Given the specific operands supplied to the Terraform expression range(2, 11, 3), ten cannot be reached by stepping from two in increments of three.
D:Given the specific operands supplied to the Terraform expression range(2, 11, 3), the range endpoint is excluded, so eleven does not appear.
Question 1040
A colleague recommends the Terraform concept "terraform fmt -recursive". Which use case best matches it?
- change whitespace and presentation without intending resource changes
- make formatting a pre-merge quality gate
- format Terraform configurations in nested local directories
- rewrite Terraform configuration into its canonical layout
- reduce insignificant whitespace changes across developers
Explanation
Correct Answer
C:The practical result of terraform fmt -recursive, used to format Terraform configurations in nested local directories, is: The recursive flag expands formatting beyond just the current directory. A qualification for this effect is: It does not fetch remote modules to reformat their source repositories.
Incorrect Answers
A:That outcome applies to Formatting preserved semantics, intended to change whitespace and presentation without intending resource changes, rather than the question's feature terraform fmt -recursive: terraform fmt standardizes language presentation instead of performing infrastructure reconciliation. Unlike Formatting preserved semantics, terraform fmt -recursive is intended to format Terraform configurations in nested local directories, not to change whitespace and presentation without intending resource changes.
B:That outcome applies to HCL style consistency in CI, intended to make formatting a pre-merge quality gate, rather than the question's feature terraform fmt -recursive: A pipeline can run fmt -check before validate and plan to enforce consistent source layout. Unlike HCL style consistency in CI, terraform fmt -recursive is intended to format Terraform configurations in nested local directories, not to make formatting a pre-merge quality gate.
D:That outcome applies to terraform fmt command, intended to rewrite Terraform configuration into its canonical layout, rather than the question's feature terraform fmt -recursive: terraform fmt formats Terraform language files consistently, including spacing and alignment. Unlike terraform fmt command, terraform fmt -recursive is intended to format Terraform configurations in nested local directories, not to rewrite Terraform configuration into its canonical layout.
E:That outcome applies to Formatting and code review noise, intended to reduce insignificant whitespace changes across developers, rather than the question's feature terraform fmt -recursive: Canonical formatting minimizes differences due solely to manual layout preferences. Unlike Formatting and code review noise, terraform fmt -recursive is intended to format Terraform configurations in nested local directories, not to reduce insignificant whitespace changes across developers.