From 73caad492cb8c6e89d3355766a46c13b14893a86 Mon Sep 17 00:00:00 2001 From: Adrien Delorme Date: Wed, 4 Nov 2020 13:31:45 +0100 Subject: [PATCH] Update custom-validation.mdx add complex example --- .../from-1.5/variables/custom-validation.mdx | 27 ++++++++++++++++++- 1 file changed, 26 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 5a9757a0f..0da062710 100644 --- a/website/pages/partials/from-1.5/variables/custom-validation.mdx +++ b/website/pages/partials/from-1.5/variables/custom-validation.mdx @@ -40,4 +40,29 @@ variable "image_id" { If `condition` evaluates to `false`, an error message including the sentences given in `error_message` will be produced. The error message string should be at least one full sentence explaining the constraint that failed, using a -sentence structure similar to the above examples. \ No newline at end of file +sentence structure similar to the above examples. + +Validation also works with more complex cases: + +```hcl +variable "image_metadata" { + + default = { + key: "value", + something: { + foo: "bar", + } + } + + validation { + condition = length(var.image_metadata.key) > 4 + error_message = "The image_metadata.key field must be more than 4 runes." + } + + validation { + condition = substr(var.image_metadata.something.foo, 0, 3) == "bar" + error_message = "The image_metadata.something.foo field must start with \"bar\"." + } + +} +```