From 5effda41704cf33334ca5918b8ccac1651df7ab0 Mon Sep 17 00:00:00 2001 From: Laura Pacilio <83350965+laurapacilio@users.noreply.github.com> Date: Wed, 30 Mar 2022 17:18:16 -0400 Subject: [PATCH] Rename page again --- website/data/language-nav-data.json | 4 +- ...dation.mdx => custom-validation-rules.mdx} | 0 website/docs/language/values/variables.mdx | 39 ++----------------- 3 files changed, 5 insertions(+), 38 deletions(-) rename website/docs/language/expressions/{custom-data-validation.mdx => custom-validation-rules.mdx} (100%) diff --git a/website/data/language-nav-data.json b/website/data/language-nav-data.json index 837a46614e..ecb6900c7b 100644 --- a/website/data/language-nav-data.json +++ b/website/data/language-nav-data.json @@ -280,8 +280,8 @@ "path": "expressions/version-constraints" }, { - "title": "Custom Data Validation", - "path": "expressions/custom-data-validation" + "title": "Custom Validation Rules", + "path": "expressions/custom-validation-rules" } ] }, diff --git a/website/docs/language/expressions/custom-data-validation.mdx b/website/docs/language/expressions/custom-validation-rules.mdx similarity index 100% rename from website/docs/language/expressions/custom-data-validation.mdx rename to website/docs/language/expressions/custom-validation-rules.mdx diff --git a/website/docs/language/values/variables.mdx b/website/docs/language/values/variables.mdx index 434c88a24f..6c2f42e06b 100644 --- a/website/docs/language/values/variables.mdx +++ b/website/docs/language/values/variables.mdx @@ -160,9 +160,7 @@ commentary for module maintainers, use comments. -> This feature was introduced in Terraform CLI v0.13.0. -In addition to Type Constraints as described above, a module author can specify -arbitrary custom validation rules for a particular variable using a `validation` -block nested within the corresponding `variable` block: +In addition to Type Constraints, you can specify custom validation rules for a particular variable using a `validation` block nested within the corresponding `variable` block. The example below checks whether the AMI ID has the correct syntax. ```hcl variable "image_id" { @@ -175,38 +173,7 @@ variable "image_id" { } } ``` - -The `condition` argument is an expression that must use the value of the -variable to return `true` if the value is valid, or `false` if it is invalid. -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](/language/functions/can) to detect such errors. For example: - -```hcl -variable "image_id" { - type = string - description = "The id of the machine image (AMI) to use for the server." - - validation { - # regex(...) fails if it cannot find a match - condition = can(regex("^ami-", var.image_id)) - error_message = "The image_id value must be a valid AMI id, starting with \"ami-\"." - } -} -``` - -If `condition` evaluates to `false`, Terraform will produce an error message -that includes the result of the `error_message` expression. The error message -should be at least one full sentence explaining the constraint that failed, -using a sentence structure similar to the above examples. - -Error messages can be literal strings, heredocs, or template expressions. The -only valid reference in an error message is the variable under validation. - -Multiple `validation` blocks can be declared in which case error messages -will be returned for _all_ failed conditions. +Refer to [Custom Data Validation](/language/expressions/custom-validation-rules) for more details. ### Suppressing Values in CLI Output @@ -319,7 +286,7 @@ may assign the value `null` to the variable. ``` variable "example" { type = string - nullable = false + nullable = false } ```