add can examples

This commit is contained in:
Adrien Delorme 2020-11-04 15:44:21 +01:00
parent 73caad492c
commit addd2da101
1 changed files with 6 additions and 1 deletions

View File

@ -22,7 +22,7 @@ The expression can refer only to the variable that the condition applies to,
and _must not_ produce errors.
If the failure of an expression is the basis of the validation decision, use
[the `can` function](./functions/can.html) to detect such errors. For example:
[the `can` function](/docs/from-1.5/functions/conversion/can) to detect such errors. For example:
```hcl
variable "image_id" {
@ -59,6 +59,11 @@ variable "image_metadata" {
error_message = "The image_metadata.key field must be more than 4 runes."
}
validation {
condition = can(var.image_metadata.something.foo)
error_message = "The image_metadata.something.foo field must exist."
}
validation {
condition = substr(var.image_metadata.something.foo, 0, 3) == "bar"
error_message = "The image_metadata.something.foo field must start with \"bar\"."