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\"." + } + +} +```