From addd2da101d13107d01b5071d32317f390ac17b0 Mon Sep 17 00:00:00 2001 From: Adrien Delorme Date: Wed, 4 Nov 2020 15:44:21 +0100 Subject: [PATCH] add can examples --- .../partials/from-1.5/variables/custom-validation.mdx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/website/pages/partials/from-1.5/variables/custom-validation.mdx b/website/pages/partials/from-1.5/variables/custom-validation.mdx index 0da062710..42af7e1d7 100644 --- a/website/pages/partials/from-1.5/variables/custom-validation.mdx +++ b/website/pages/partials/from-1.5/variables/custom-validation.mdx @@ -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\"."