From bb35f02c9519ab5adff073682efd822ff7f0edb9 Mon Sep 17 00:00:00 2001 From: Alisdair McDiarmid Date: Mon, 4 Apr 2022 10:56:51 -0400 Subject: [PATCH] Conclude preconditions/postconditions experiment --- .../testdata/show-json/conditions/main.tf | 4 -- internal/configs/experiments.go | 49 ------------------- ...preconditions-postconditions-experiment.tf | 34 ------------- .../preconditions-postconditions.tf} | 4 -- internal/experiments/experiment.go | 2 +- internal/terraform/context_apply2_test.go | 4 -- internal/terraform/context_plan2_test.go | 20 -------- internal/terraform/context_validate_test.go | 32 ------------ 8 files changed, 1 insertion(+), 148 deletions(-) delete mode 100644 internal/configs/testdata/invalid-modules/preconditions-postconditions-experiment/preconditions-postconditions-experiment.tf rename internal/configs/testdata/{warning-files/preconditions-postconditions-experiment.tf => valid-files/preconditions-postconditions.tf} (82%) diff --git a/internal/command/testdata/show-json/conditions/main.tf b/internal/command/testdata/show-json/conditions/main.tf index 78566ff522..f63dca9fcd 100644 --- a/internal/command/testdata/show-json/conditions/main.tf +++ b/internal/command/testdata/show-json/conditions/main.tf @@ -1,7 +1,3 @@ -terraform { - experiments = [preconditions_postconditions] -} - variable "ami" { type = string default = "ami-test" diff --git a/internal/configs/experiments.go b/internal/configs/experiments.go index 9175fd01fc..2ebf2d7006 100644 --- a/internal/configs/experiments.go +++ b/internal/configs/experiments.go @@ -209,55 +209,6 @@ func checkModuleExperiments(m *Module) hcl.Diagnostics { } } - if !m.ActiveExperiments.Has(experiments.PreconditionsPostconditions) { - for _, r := range m.ManagedResources { - for _, c := range r.Preconditions { - diags = diags.Append(&hcl.Diagnostic{ - Severity: hcl.DiagError, - Summary: "Preconditions are experimental", - Detail: "The resource preconditions 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 preconditions_postconditions to the list of active experiments.", - Subject: c.DeclRange.Ptr(), - }) - } - for _, c := range r.Postconditions { - diags = diags.Append(&hcl.Diagnostic{ - Severity: hcl.DiagError, - Summary: "Postconditions are experimental", - Detail: "The resource preconditions 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 preconditions_postconditions to the list of active experiments.", - Subject: c.DeclRange.Ptr(), - }) - } - } - for _, r := range m.DataResources { - for _, c := range r.Preconditions { - diags = diags.Append(&hcl.Diagnostic{ - Severity: hcl.DiagError, - Summary: "Preconditions are experimental", - Detail: "The resource preconditions 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 preconditions_postconditions to the list of active experiments.", - Subject: c.DeclRange.Ptr(), - }) - } - for _, c := range r.Postconditions { - diags = diags.Append(&hcl.Diagnostic{ - Severity: hcl.DiagError, - Summary: "Postconditions are experimental", - Detail: "The resource preconditions 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 preconditions_postconditions to the list of active experiments.", - Subject: c.DeclRange.Ptr(), - }) - } - } - for _, o := range m.Outputs { - for _, c := range o.Preconditions { - diags = diags.Append(&hcl.Diagnostic{ - Severity: hcl.DiagError, - Summary: "Preconditions are experimental", - Detail: "The output value preconditions 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 preconditions_postconditions to the list of active experiments.", - Subject: c.DeclRange.Ptr(), - }) - } - } - } - return diags } diff --git a/internal/configs/testdata/invalid-modules/preconditions-postconditions-experiment/preconditions-postconditions-experiment.tf b/internal/configs/testdata/invalid-modules/preconditions-postconditions-experiment/preconditions-postconditions-experiment.tf deleted file mode 100644 index 8b63e77f37..0000000000 --- a/internal/configs/testdata/invalid-modules/preconditions-postconditions-experiment/preconditions-postconditions-experiment.tf +++ /dev/null @@ -1,34 +0,0 @@ -resource "test" "test" { - lifecycle { - precondition { # ERROR: Preconditions are experimental - condition = path.module != "" - error_message = "Must be true." - } - postcondition { # ERROR: Postconditions are experimental - condition = path.module != "" - error_message = "Must be true." - } - } -} - -data "test" "test" { - lifecycle { - precondition { # ERROR: Preconditions are experimental - condition = path.module != "" - error_message = "Must be true." - } - postcondition { # ERROR: Postconditions are experimental - condition = path.module != "" - error_message = "Must be true." - } - } -} - -output "test" { - value = "" - - precondition { # ERROR: Preconditions are experimental - condition = path.module != "" - error_message = "Must be true." - } -} diff --git a/internal/configs/testdata/warning-files/preconditions-postconditions-experiment.tf b/internal/configs/testdata/valid-files/preconditions-postconditions.tf similarity index 82% rename from internal/configs/testdata/warning-files/preconditions-postconditions-experiment.tf rename to internal/configs/testdata/valid-files/preconditions-postconditions.tf index 35dac3472c..6f48840a8b 100644 --- a/internal/configs/testdata/warning-files/preconditions-postconditions-experiment.tf +++ b/internal/configs/testdata/valid-files/preconditions-postconditions.tf @@ -1,7 +1,3 @@ -terraform { - experiments = [preconditions_postconditions] # WARNING: Experimental feature "preconditions_postconditions" is active -} - resource "test" "test" { lifecycle { precondition { diff --git a/internal/experiments/experiment.go b/internal/experiments/experiment.go index fcdcad8047..b5d67f58b3 100644 --- a/internal/experiments/experiment.go +++ b/internal/experiments/experiment.go @@ -26,8 +26,8 @@ func init() { registerConcludedExperiment(VariableValidation, "Custom variable validation can now be used by default, without enabling an experiment.") registerConcludedExperiment(SuppressProviderSensitiveAttrs, "Provider-defined sensitive attributes are now redacted by default, without enabling an experiment.") registerConcludedExperiment(ConfigDrivenMove, "Declarations of moved resource instances using \"moved\" blocks can now be used by default, without enabling an experiment.") + registerConcludedExperiment(PreconditionsPostconditions, "Condition blocks can now be used by default, without enabling an experiment.") registerCurrentExperiment(ModuleVariableOptionalAttrs) - registerCurrentExperiment(PreconditionsPostconditions) } // GetCurrent takes an experiment name and returns the experiment value diff --git a/internal/terraform/context_apply2_test.go b/internal/terraform/context_apply2_test.go index 38b9d26f67..f2cc27de35 100644 --- a/internal/terraform/context_apply2_test.go +++ b/internal/terraform/context_apply2_test.go @@ -741,10 +741,6 @@ resource "test_object" "b" { func TestContext2Apply_resourcePostcondition(t *testing.T) { m := testModuleInline(t, map[string]string{ "main.tf": ` -terraform { - experiments = [preconditions_postconditions] -} - variable "boop" { type = string } diff --git a/internal/terraform/context_plan2_test.go b/internal/terraform/context_plan2_test.go index ab707a3a4c..b5c65d8ee8 100644 --- a/internal/terraform/context_plan2_test.go +++ b/internal/terraform/context_plan2_test.go @@ -2182,10 +2182,6 @@ func TestContext2Plan_moduleExpandOrphansResourceInstance(t *testing.T) { func TestContext2Plan_resourcePreconditionPostcondition(t *testing.T) { m := testModuleInline(t, map[string]string{ "main.tf": ` -terraform { - experiments = [preconditions_postconditions] -} - variable "boop" { type = string } @@ -2445,10 +2441,6 @@ resource "test_resource" "a" { func TestContext2Plan_dataSourcePreconditionPostcondition(t *testing.T) { m := testModuleInline(t, map[string]string{ "main.tf": ` -terraform { - experiments = [preconditions_postconditions] -} - variable "boop" { type = string } @@ -2714,10 +2706,6 @@ resource "test_resource" "a" { func TestContext2Plan_outputPrecondition(t *testing.T) { m := testModuleInline(t, map[string]string{ "main.tf": ` -terraform { - experiments = [preconditions_postconditions] -} - variable "boop" { type = string } @@ -2883,10 +2871,6 @@ func TestContext2Plan_preconditionErrors(t *testing.T) { for _, tc := range testCases { t.Run(tc.condition, func(t *testing.T) { main := fmt.Sprintf(` - terraform { - experiments = [preconditions_postconditions] - } - resource "test_resource" "a" { value = var.boop lifecycle { @@ -2932,10 +2916,6 @@ func TestContext2Plan_preconditionSensitiveValues(t *testing.T) { m := testModuleInline(t, map[string]string{ "main.tf": ` -terraform { - experiments = [preconditions_postconditions] -} - variable "boop" { sensitive = true type = string diff --git a/internal/terraform/context_validate_test.go b/internal/terraform/context_validate_test.go index 5b6b98da8e..cb1e31fe4b 100644 --- a/internal/terraform/context_validate_test.go +++ b/internal/terraform/context_validate_test.go @@ -2109,10 +2109,6 @@ func TestContext2Validate_precondition_good(t *testing.T) { }) m := testModuleInline(t, map[string]string{ "main.tf": ` -terraform { - experiments = [preconditions_postconditions] -} - variable "input" { type = string default = "foo" @@ -2156,10 +2152,6 @@ func TestContext2Validate_precondition_badCondition(t *testing.T) { }) m := testModuleInline(t, map[string]string{ "main.tf": ` -terraform { - experiments = [preconditions_postconditions] -} - variable "input" { type = string default = "foo" @@ -2206,10 +2198,6 @@ func TestContext2Validate_precondition_badErrorMessage(t *testing.T) { }) m := testModuleInline(t, map[string]string{ "main.tf": ` -terraform { - experiments = [preconditions_postconditions] -} - variable "input" { type = string default = "foo" @@ -2256,10 +2244,6 @@ func TestContext2Validate_postcondition_good(t *testing.T) { }) m := testModuleInline(t, map[string]string{ "main.tf": ` -terraform { - experiments = [preconditions_postconditions] -} - resource "aws_instance" "test" { foo = "foo" @@ -2304,10 +2288,6 @@ func TestContext2Validate_postcondition_badCondition(t *testing.T) { // an input variable. m := testModuleInline(t, map[string]string{ "main.tf": ` -terraform { - experiments = [preconditions_postconditions] -} - variable "input" { type = string default = "foo" @@ -2354,10 +2334,6 @@ func TestContext2Validate_postcondition_badErrorMessage(t *testing.T) { }) m := testModuleInline(t, map[string]string{ "main.tf": ` -terraform { - experiments = [preconditions_postconditions] -} - resource "aws_instance" "test" { foo = "foo" @@ -2399,10 +2375,6 @@ func TestContext2Validate_precondition_count(t *testing.T) { }) m := testModuleInline(t, map[string]string{ "main.tf": ` -terraform { - experiments = [preconditions_postconditions] -} - locals { foos = ["bar", "baz"] } @@ -2446,10 +2418,6 @@ func TestContext2Validate_postcondition_forEach(t *testing.T) { }) m := testModuleInline(t, map[string]string{ "main.tf": ` -terraform { - experiments = [preconditions_postconditions] -} - locals { foos = toset(["bar", "baz", "boop"]) }