View Full HashiCorp Terraform Associate 004 Exam Dumps and Practice Test Dumps.
Q241. Which Terraform function returns true when a string begins with specified text
- endswith
- strcontains
- startswith
- regexall
Correct Answer: 3. startswith
Explanation
The startswith function checks whether a string begins with a specified sequence of characters and returns a boolean result. endswith checks the end of a string. strcontains checks whether text occurs anywhere within a string. regexall finds all matches for a regular expression. startswith is therefore the correct answer because Terraform validation and conditional expressions may need to confirm that names identifiers or paths begin with an approved prefix. This can help enforce consistent naming conventions without requiring a more complex regular expression. The comparison remains case sensitive, so input normalization may be required when capitalization should not matter.
Q242. Which Terraform function returns the first nonempty list from several list arguments
- coalescelist
- concat
- flatten
- compact
Correct Answer: 1. coalescelist
Explanation
The coalescelist function returns the first supplied list that contains at least one element. concat combines lists together. flatten converts nested lists into one list. compact removes empty string values from a list of strings. coalescelist is therefore the correct answer because modules sometimes need to choose a preferred collection and fall back to another when the preferred one is empty. The supplied arguments should have compatible element types so Terraform can determine a consistent result. This function provides a concise alternative to longer conditional expressions when the desired logic is simply to select the first available nonempty list.
Q243. Which Terraform function raises one number to the power of another
- log
- signum
- ceil
- pow
Correct Answer: 4. pow
Explanation
The pow function calculates one number raised to the power of another number. log calculates a logarithm using a specified base. signum reports whether a number is negative zero or positive. ceil rounds a number upward. pow is therefore the correct answer because Terraform expressions can perform mathematical calculations directly when infrastructure sizing or derived numeric values require exponentiation. Mathematical expressions should remain easy to understand because overly complex calculations can make infrastructure configuration harder to review. The resulting value must also satisfy the type and range requirements of the provider argument where it is eventually used.
Q244. Which Terraform function determines whether specified text occurs anywhere inside another string
- startswith
- strcontains
- endswith
- substr
Correct Answer: 2. strcontains
Explanation
The strcontains function checks whether one string contains another specified string and returns a boolean result. startswith checks only the beginning of a string. endswith checks only the end. substr extracts characters based on position and length. strcontains is therefore the correct answer because validation logic may need to determine whether a naming value label or other text contains an expected sequence. It is simpler than using a regular expression when only literal substring detection is required. Users should remember that matching is case sensitive unless the strings are normalized before the comparison.
Q245. Which Terraform function returns true when a string finishes with specified text
- endswith
- startswith
- strcontains
- trimspace
Correct Answer: 1. endswith
Explanation
The endswith function checks whether a string ends with the specified sequence of characters. startswith checks the beginning. strcontains checks whether text occurs anywhere in the string. trimspace removes leading and trailing whitespace. endswith is therefore the correct answer because Terraform validation may need to enforce suffix based conventions for resource names file names or identifiers. It provides a clearer expression than a regular expression when only the final characters matter. As with other string comparison functions, the comparison is case sensitive and should be combined with case normalization when required by the intended naming standard.
Q246. Which Terraform function returns the logarithm of a number using a specified base
- pow
- abs
- log
- floor
Correct Answer: 3. log
Explanation
The log function calculates the logarithm of a number using a supplied base. pow performs exponentiation. abs returns the absolute value of a number. floor rounds a numeric value downward. log is therefore the correct answer because Terraform supports mathematical functions that can derive configuration values without external scripts. Although logarithms are less common than basic arithmetic in infrastructure definitions, they may be useful in calculated sizing or specialized module logic. Module authors should keep such calculations well documented so users can understand how input values affect the resulting infrastructure configuration.
Q247. Which Terraform function converts a string representation of an integer using a specified base
- tonumber
- parseint
- tostring
- format
Correct Answer: 2. parseint
Explanation
The parseint function converts a string containing an integer representation into a Terraform number using a specified numeric base. tonumber performs more general numeric conversion without the same explicit base behavior. tostring converts values into text. format creates formatted strings. parseint is therefore the correct answer because configuration may occasionally receive numeric values represented in decimal hexadecimal or another base. The source string must be valid for the selected base. Clear input validation is useful when the value comes from module callers or external data so invalid numeric text is rejected with an understandable error.
Q248. Which Terraform function returns whether a number is negative zero or positive
- abs
- floor
- max
- signum
Correct Answer: 4. signum
Explanation
The signum function returns a value representing whether the supplied number is negative zero or positive. abs returns the magnitude without a negative sign. floor rounds downward. max selects the largest value from supplied arguments. signum is therefore the correct answer because Terraform expressions may need to branch or validate based on the direction of a numeric value rather than its exact magnitude. Although this is less common in simple infrastructure configurations, it can be useful in reusable modules with calculated numeric inputs. The result can then participate in conditional expressions or validation logic.
Q249. Which Terraform function compresses a string using gzip and returns Base64 encoded output
- base64gzip
- base64encode
- filebase64
- gzipdecode
Correct Answer: 1. base64gzip
Explanation
The base64gzip function compresses a string using gzip and then returns the compressed bytes in Base64 encoded form. base64encode performs encoding without compression. filebase64 reads a file and returns its contents encoded as Base64. gzipdecode is not the relevant Terraform function for this operation. base64gzip is therefore the correct answer because some infrastructure services accept compressed user data or configuration payloads in Base64 representation. Compression can reduce payload size, but users should confirm that the receiving platform expects gzip compressed data rather than ordinary Base64 encoded text.
Q250. Which Terraform function converts a string to title style capitalization
- upper
- title
- lower
- format
Correct Answer: 2. title
Explanation
The title function converts words in a string into title style capitalization. upper converts all alphabetic characters to uppercase. lower converts them to lowercase. format creates strings from a formatting specification. title is therefore the correct answer because Terraform expressions may need human readable labels or normalized display values. This function should not automatically be used for infrastructure identifiers because capitalization changes can alter names or violate provider restrictions. Module authors should distinguish between display labels and stable resource names when applying text transformation functions.
Q251. Which Terraform function returns the hexadecimal SHA1 hash of a local file
- filesha256
- filebase64sha1
- filesha1
- sha1
Correct Answer: 3. filesha1
Explanation
The filesha1 function reads a local file and calculates its SHA1 hash in hexadecimal form. filesha256 uses the SHA256 algorithm. filebase64sha1 returns a SHA1 file hash in Base64 form. sha1 hashes a supplied string rather than directly reading a file. filesha1 is therefore the correct answer because some provider resources or external systems may require a checksum of file content. SHA1 is no longer preferred for security sensitive cryptographic purposes because of known collision weaknesses. It should generally be used only when compatibility with an existing system specifically requires it.
Q252. Which Terraform function returns the hexadecimal SHA512 hash of a local file
- sha512
- filebase64sha512
- filesha256
- filesha512
Correct Answer: 4. filesha512
Explanation
The filesha512 function calculates the SHA512 hash of a local file and returns the result in hexadecimal representation. sha512 hashes a string rather than a file. filebase64sha512 returns the file hash encoded in Base64. filesha256 uses a different hashing algorithm. filesha512 is therefore the correct answer because configurations sometimes need a strong deterministic checksum for an artifact before providing it to a resource or external service. The referenced file must already exist when Terraform evaluates the expression because functions cannot depend on files that are created later during the same apply.
Q253. Which Terraform command can produce shell completion scripts for supported shells
- terraform metadata functions
- terraform completion
- terraform providers
- terraform console
Correct Answer: 2. terraform completion
Explanation
terraform completion provides shell completion support for Terraform commands in supported command line environments. terraform metadata functions is used for different metadata related purposes. terraform providers displays provider requirements. terraform console evaluates Terraform expressions interactively. terraform completion is therefore the correct answer because command completion can make frequent Terraform CLI usage faster and reduce typing errors. The exact setup depends on the shell being used. This feature affects command line convenience only and does not change Terraform configuration state planning behavior or infrastructure resources.
Q254. Which Terraform function generates a namespaced UUID from a namespace and name
- uuidv5
- uuid
- md5
- sha256
Correct Answer: 1. uuidv5
Explanation
The uuidv5 function generates a deterministic namespaced UUID using a namespace identifier and a name value. uuid generates a new UUID value without the same deterministic namespace based behavior. md5 and sha256 are hashing functions rather than UUID generators. uuidv5 is therefore the correct answer because the same namespace and name combination produces the same UUID result. This can be useful when configuration needs a stable unique identifier derived from known input values. Deterministic identifiers should still be chosen carefully so changes to the name input do not unintentionally alter resource identity.
Q255. Which Terraform function removes a specified prefix from a string when that prefix is present
- trimsuffix
- trimspace
- trimprefix
- replace
Correct Answer: 3. trimprefix
Explanation
The trimprefix function removes a specified prefix from the beginning of a string when the string starts with that prefix. trimsuffix performs the corresponding operation at the end. trimspace removes surrounding whitespace. replace substitutes matching text more generally. trimprefix is therefore the correct answer because configuration may need to normalize identifiers or paths that optionally include a known prefix. This function is clearer than a general replacement when only the beginning of the string should be affected and prevents matching occurrences elsewhere from being changed unintentionally.
Q256. Which Terraform function removes a specified suffix from a string when that suffix is present
- trimprefix
- trimsuffix
- chomp
- substr
Correct Answer: 2. trimsuffix
Explanation
The trimsuffix function removes a specified suffix from the end of a string when it is present. trimprefix removes matching text from the beginning. chomp removes newline characters from the end of a string. substr extracts a section based on position and length. trimsuffix is therefore the correct answer because Terraform configurations may need to remove known extensions environment suffixes or other final text without affecting matching characters elsewhere. It provides a direct and readable way to normalize values before they are passed to other expressions or resources.
Q257. Which HCP Terraform feature controls which users or teams can perform workspace actions
- Team permissions
- Provider constraints
- State serial numbers
- Resource lifecycle
Correct Answer: 1. Team permissions
Explanation
Team permissions determine which users or teams can perform actions within HCP Terraform workspaces and related organizational resources. Provider constraints control compatible provider versions. State serial numbers identify state revisions. Resource lifecycle settings affect managed infrastructure behavior. Team permissions is therefore the correct answer because collaborative Terraform environments need controlled access to planning applying configuration state and administration capabilities. Organizations should follow least privilege principles so users receive only the access necessary for their responsibilities. Permissions should also be reviewed when team membership or operational ownership changes.
Q258. Which HCP Terraform concept ensures workspace runs execute one at a time in an ordered sequence
- Variable sets
- Run queue
- Private registry
- Cost estimation
Correct Answer: 2. Run queue
Explanation
The run queue organizes Terraform runs for a workspace so operations affecting the same workspace are processed in a controlled sequence rather than modifying state concurrently. Variable sets distribute common values. Private registry hosts reusable modules and providers. Cost estimation evaluates potential infrastructure cost. Run queue is therefore the correct answer because multiple users or automation systems may request runs close together. Serializing workspace operations protects state consistency and ensures later runs consider infrastructure changes produced by earlier ones before they proceed through planning and application.
Q259. Which Terraform function removes surrounding characters specified in a character set from a string
- trimspace
- trimprefix
- trimsuffix
- trim
Correct Answer: 4. trim
Explanation
The trim function removes characters from both ends of a string according to a supplied set of characters. trimspace removes surrounding whitespace specifically. trimprefix removes one specified prefix. trimsuffix removes one specified suffix. trim is therefore the correct answer because it provides flexible cleanup when several possible surrounding characters should be removed. Users should understand that the second argument describes characters to remove rather than one exact beginning or ending substring. When an exact prefix or suffix must be removed, the more specific functions usually make the configuration intention clearer.
Q260. Which Terraform function returns a Base64 encoded SHA256 hash of a string
- sha256
- filebase64sha256
- base64sha256
- base64encode
Correct Answer: 3. base64sha256
Explanation
The base64sha256 function calculates the SHA256 hash of a supplied string and returns the resulting hash in Base64 representation. sha256 returns a hexadecimal SHA256 hash. filebase64sha256 hashes file contents rather than a supplied string. base64encode converts the original string into Base64 without calculating a hash. base64sha256 is therefore the correct answer because some APIs and resources require SHA256 fingerprint values encoded with Base64. Hashing is not encryption and does not make confidential source information safe to expose if the input itself remains available elsewhere.