From d1bc4122202a9b9b7d9f642a1a7493e64f513119 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Wed, 27 May 2020 11:56:15 -0700 Subject: [PATCH] configs: Custom variable validation is no longer experimental All of the feedback from the experiment described enhancements that can potentially be added later without breaking changes, so this change simply removes the experiment gate from the feature as originally implemented with no changes to its functionality. Further enhancements may follow in later releases, but the goal of this change is just to ship the feature exactly as it was under the experiment. Most of the changes here are cleaning up the experiment opt-ins from our test cases. The most important parts are in configs/experiments.go and in experiments/experiment.go . --- configs/experiments.go | 13 ------------- .../invalid-files/variable-validation-bad-msg.tf | 5 ----- .../variable-validation-condition-badref.tf | 4 ---- .../variable-validation-condition-noref.tf | 4 ---- .../variable-validation-without-optin.tf | 7 ------- .../variable_validation.tf} | 4 ---- experiments/experiment.go | 2 +- terraform/context_validate_test.go | 8 -------- .../child/child.tf | 8 -------- website/docs/configuration/functions/can.html.md | 2 +- website/docs/configuration/variables.html.md | 14 +------------- 11 files changed, 3 insertions(+), 68 deletions(-) delete mode 100644 configs/testdata/invalid-modules/variable-validation-without-optin/variable-validation-without-optin.tf rename configs/testdata/{warning-files/variable_validation_experiment.tf => valid-files/variable_validation.tf} (50%) diff --git a/configs/experiments.go b/configs/experiments.go index 435bac11d4..8af1e951f1 100644 --- a/configs/experiments.go +++ b/configs/experiments.go @@ -139,18 +139,5 @@ func checkModuleExperiments(m *Module) hcl.Diagnostics { } */ - if !m.ActiveExperiments.Has(experiments.VariableValidation) { - for _, vc := range m.Variables { - if len(vc.Validations) != 0 { - diags = diags.Append(&hcl.Diagnostic{ - Severity: hcl.DiagError, - Summary: "Custom variable validation is experimental", - Detail: "This feature is currently an opt-in experiment, subject to change in future releases based on feedback.\n\nActivate the feature for this module by adding variable_validation to the list of active experiments.", - Subject: vc.Validations[0].DeclRange.Ptr(), - }) - } - } - } - return diags } diff --git a/configs/testdata/invalid-files/variable-validation-bad-msg.tf b/configs/testdata/invalid-files/variable-validation-bad-msg.tf index 37ec496c02..65df45579c 100644 --- a/configs/testdata/invalid-files/variable-validation-bad-msg.tf +++ b/configs/testdata/invalid-files/variable-validation-bad-msg.tf @@ -1,8 +1,3 @@ - -terraform { - experiments = [variable_validation] -} - variable "validation" { validation { condition = var.validation != 4 diff --git a/configs/testdata/invalid-files/variable-validation-condition-badref.tf b/configs/testdata/invalid-files/variable-validation-condition-badref.tf index de88ced7a4..42f4aa5f25 100644 --- a/configs/testdata/invalid-files/variable-validation-condition-badref.tf +++ b/configs/testdata/invalid-files/variable-validation-condition-badref.tf @@ -1,8 +1,4 @@ -terraform { - experiments = [variable_validation] -} - locals { foo = 1 } diff --git a/configs/testdata/invalid-files/variable-validation-condition-noref.tf b/configs/testdata/invalid-files/variable-validation-condition-noref.tf index e6b217b145..6eee91337f 100644 --- a/configs/testdata/invalid-files/variable-validation-condition-noref.tf +++ b/configs/testdata/invalid-files/variable-validation-condition-noref.tf @@ -1,8 +1,4 @@ -terraform { - experiments = [variable_validation] -} - variable "validation" { validation { condition = true # ERROR: Invalid variable validation condition diff --git a/configs/testdata/invalid-modules/variable-validation-without-optin/variable-validation-without-optin.tf b/configs/testdata/invalid-modules/variable-validation-without-optin/variable-validation-without-optin.tf deleted file mode 100644 index 655f2cd4ee..0000000000 --- a/configs/testdata/invalid-modules/variable-validation-without-optin/variable-validation-without-optin.tf +++ /dev/null @@ -1,7 +0,0 @@ - -variable "validation_without_optin" { - validation { # ERROR: Custom variable validation is experimental - condition = var.validation_without_optin != 4 - error_message = "Must not be four." - } -} diff --git a/configs/testdata/warning-files/variable_validation_experiment.tf b/configs/testdata/valid-files/variable_validation.tf similarity index 50% rename from configs/testdata/warning-files/variable_validation_experiment.tf rename to configs/testdata/valid-files/variable_validation.tf index 28c285ad2c..0a0c2dd50e 100644 --- a/configs/testdata/warning-files/variable_validation_experiment.tf +++ b/configs/testdata/valid-files/variable_validation.tf @@ -1,7 +1,3 @@ -terraform { - experiments = [variable_validation] # WARNING: Experimental feature "variable_validation" is active -} - variable "validation" { validation { condition = var.validation == 5 diff --git a/experiments/experiment.go b/experiments/experiment.go index 037b34e732..cac7d54fc2 100644 --- a/experiments/experiment.go +++ b/experiments/experiment.go @@ -19,7 +19,7 @@ const ( func init() { // Each experiment constant defined above must be registered here as either // a current or a concluded experiment. - registerCurrentExperiment(VariableValidation) + registerConcludedExperiment(VariableValidation, "Custom variable validation can now be used by default, without enabling an experiment.") } // GetCurrent takes an experiment name and returns the experiment value diff --git a/terraform/context_validate_test.go b/terraform/context_validate_test.go index f811dfcadc..657daa7360 100644 --- a/terraform/context_validate_test.go +++ b/terraform/context_validate_test.go @@ -1371,14 +1371,6 @@ func TestContext2Validate_variableCustomValidationsRoot(t *testing.T) { // altogether. (Root module variables are never known during validation.) m := testModuleInline(t, map[string]string{ "main.tf": ` -# This feature is currently experimental. -# (If you're currently cleaning up after concluding the experiment, -# remember to also clean up similar references in the configs package -# under "invalid-files" and "invalid-modules".) -terraform { - experiments = [variable_validation] -} - variable "test" { type = string diff --git a/terraform/testdata/validate-variable-custom-validations-child/child/child.tf b/terraform/testdata/validate-variable-custom-validations-child/child/child.tf index 88598e042a..05027f75ad 100644 --- a/terraform/testdata/validate-variable-custom-validations-child/child/child.tf +++ b/terraform/testdata/validate-variable-custom-validations-child/child/child.tf @@ -1,11 +1,3 @@ -# This feature is currently experimental. -# (If you're currently cleaning up after concluding the experiment, -# remember to also clean up similar references in the configs package -# under "invalid-files" and "invalid-modules".) -terraform { - experiments = [variable_validation] -} - variable "test" { type = string diff --git a/website/docs/configuration/functions/can.html.md b/website/docs/configuration/functions/can.html.md index c957020cbd..5cb3abb618 100644 --- a/website/docs/configuration/functions/can.html.md +++ b/website/docs/configuration/functions/can.html.md @@ -30,7 +30,7 @@ For example: variable "timestamp" { type = string - validation { # NOTE: custom validation is currently an opt-in experiment (see link above) + validation { # formatdate fails if the second argument is not a valid timestamp condition = can(formatdate("", var.timestamp)) error_message = "The timestamp argument requires a valid RFC 3339 timestamp." diff --git a/website/docs/configuration/variables.html.md b/website/docs/configuration/variables.html.md index 993eeb3d92..1632c6e707 100644 --- a/website/docs/configuration/variables.html.md +++ b/website/docs/configuration/variables.html.md @@ -166,9 +166,7 @@ commentary for module maintainers, use comments. ## Custom Validation Rules -~> *Warning:* This feature is currently experimental and is subject to breaking -changes even in minor releases. We welcome your feedback, but cannot -recommend using this feature in production modules yet. +-> 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` @@ -212,16 +210,6 @@ that includes the sentences given in `error_message`. 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. -This is [an experimental language feature](./terraform.html#experimental-language-features) -that currently requires an explicit opt-in using the experiment keyword -`variable_validation`: - -```hcl -terraform { - experiments = [variable_validation] -} -``` - ## Assigning Values to Root Module Variables When variables are declared in the root module of your configuration, they