-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

HashiCorp Terraform Associate (003) Exam Guide
By :

This section will cover type conversion functions, as highlighted previously. They will be useful to ensure that input values are always compatible with the written configuration scripts, so they can be handled with the right validations.
The examples used in the section will be available with the filename 5. type-conversion-functions.txt
in the GitHub link provided at the start of this chapter.
The can()
function is mainly used to validate whether the expression will produce a valid result or not. If a valid result is possible, true
is returned; otherwise, false
will be returned.
You can now take a look at a couple of examples:
$ can(anytrue([true, false]))
> true
$ can(one([1, 2]))
> false
Here, the anytrue()
function will always return a result, so the can()
output is true
. In the second case, the one()
function will throw an error if the input list has more than one element, and hence the function returns...