Conclude preconditions/postconditions experiment

This commit is contained in:
Alisdair McDiarmid 2022-04-04 10:56:51 -04:00
parent 3fbedf2543
commit bb35f02c95
8 changed files with 1 additions and 148 deletions

View File

@ -1,7 +1,3 @@
terraform {
experiments = [preconditions_postconditions]
}
variable "ami" {
type = string
default = "ami-test"

View File

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

View File

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

View File

@ -1,7 +1,3 @@
terraform {
experiments = [preconditions_postconditions] # WARNING: Experimental feature "preconditions_postconditions" is active
}
resource "test" "test" {
lifecycle {
precondition {

View File

@ -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

View File

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

View File

@ -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

View File

@ -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"])
}