Terraform-Associate-004 practice question 17 of 35
You have a list of numbers that represents the number of free CPU cores on each virtual cluster: numcpus = [ 18, 3, 7, 11, 2 ] What Terraform function could you use to select the largest number from the list?
Full set: 360 questionsThe max function in Terraform is a built-in numeric function designed to find the greatest value from a set of numbers. It can accept multiple number arguments or a single list/set of numbers. When provided with the list [18, 3, 7, 11, 2], max(numcpus) will correctly evaluate the elements and return the largest value, which is 18. This directly addresses the requirement of selecting the largest number from the list.
A. top(numcpus) is incorrect because top is not a valid built-in function in the Terraform language.
C. ceil(numcpus) is incorrect as the ceil function rounds a single number up to the nearest integer; it does not operate on a list to find the maximum value.
D. hight[numcpus] is incorrect because hight is not a Terraform function, and the syntax is invalid for a function call.
1. HashiCorp. (n.d.). Terraform Language: max Function. Terraform by HashiCorp. Retrieved from https://developer.hashicorp.com/terraform/language/functions/max
Section: max Function Documentation. This page explicitly states, "max takes one or more numbers and returns the greatest number from the set." It also shows an example of its usage with a list: > max([5, 12, 9]).
2. HashiCorp. (n.d.). Terraform Language: ceil Function. Terraform by HashiCorp. Retrieved from https://developer.hashicorp.com/terraform/language/functions/ceil
Section: ceil Function Documentation. This page defines ceil as a function that "returns the closest integer that is greater than or equal to the given value," confirming it operates on a single number for rounding, not on a list for comparison.
3. HashiCorp. (n.d.). Terraform Language: Functions. Terraform by HashiCorp. Retrieved from https://developer.hashicorp.com/terraform/language/functions
Section: All Functions. A review of the complete list of built-in functions confirms that top and hight are not valid Terraform functions.
Keep practicing
Take the free Terraform-Associate-004 practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other Terraform-Associate-004 practice questions
- Question 1You should run terraform fnt to rewrite all Terraform configurations within the current w…
- Question 2Module variable assignments are inherited from the parent module and you do not need to e…
- Question 3terraform validate confirms thesyntaxof Terraform files.
- Question 4Using the terraform state rm command against a resource will destroy it.
- Question 5Variables declared within a module are accessible outside of the module.
- Question 6terraform init retrieves and caches the configuration for all remote modules.
