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 .
This commit is contained in:
Martin Atkins 2020-05-27 11:56:15 -07:00
parent 01f91316da
commit d1bc412220
11 changed files with 3 additions and 68 deletions

View File

@ -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 return diags
} }

View File

@ -1,8 +1,3 @@
terraform {
experiments = [variable_validation]
}
variable "validation" { variable "validation" {
validation { validation {
condition = var.validation != 4 condition = var.validation != 4

View File

@ -1,8 +1,4 @@
terraform {
experiments = [variable_validation]
}
locals { locals {
foo = 1 foo = 1
} }

View File

@ -1,8 +1,4 @@
terraform {
experiments = [variable_validation]
}
variable "validation" { variable "validation" {
validation { validation {
condition = true # ERROR: Invalid variable validation condition condition = true # ERROR: Invalid variable validation condition

View File

@ -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."
}
}

View File

@ -1,7 +1,3 @@
terraform {
experiments = [variable_validation] # WARNING: Experimental feature "variable_validation" is active
}
variable "validation" { variable "validation" {
validation { validation {
condition = var.validation == 5 condition = var.validation == 5

View File

@ -19,7 +19,7 @@ const (
func init() { func init() {
// Each experiment constant defined above must be registered here as either // Each experiment constant defined above must be registered here as either
// a current or a concluded experiment. // 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 // GetCurrent takes an experiment name and returns the experiment value

View File

@ -1371,14 +1371,6 @@ func TestContext2Validate_variableCustomValidationsRoot(t *testing.T) {
// altogether. (Root module variables are never known during validation.) // altogether. (Root module variables are never known during validation.)
m := testModuleInline(t, map[string]string{ m := testModuleInline(t, map[string]string{
"main.tf": ` "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" { variable "test" {
type = string type = string

View File

@ -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" { variable "test" {
type = string type = string

View File

@ -30,7 +30,7 @@ For example:
variable "timestamp" { variable "timestamp" {
type = string 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 # formatdate fails if the second argument is not a valid timestamp
condition = can(formatdate("", var.timestamp)) condition = can(formatdate("", var.timestamp))
error_message = "The timestamp argument requires a valid RFC 3339 timestamp." error_message = "The timestamp argument requires a valid RFC 3339 timestamp."

View File

@ -166,9 +166,7 @@ commentary for module maintainers, use comments.
## Custom Validation Rules ## Custom Validation Rules
~> *Warning:* This feature is currently experimental and is subject to breaking -> This feature was introduced in Terraform CLI v0.13.0.
changes even in minor releases. We welcome your feedback, but cannot
recommend using this feature in production modules yet.
In addition to Type Constraints as described above, a module author can specify In addition to Type Constraints as described above, a module author can specify
arbitrary custom validation rules for a particular variable using a `validation` 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, should be at least one full sentence explaining the constraint that failed,
using a sentence structure similar to the above examples. 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 ## Assigning Values to Root Module Variables
When variables are declared in the root module of your configuration, they When variables are declared in the root module of your configuration, they