From c182f04e936e79342ee6fd699c6176c381748247 Mon Sep 17 00:00:00 2001 From: James Pogran Date: Mon, 1 Apr 2024 09:12:33 -0400 Subject: [PATCH 1/3] Conclude Terraform Experiments Completion This commit concludes the work on the Terraform experiments feature by removing the list of features from completion for the `experiments` attriubute. Terraform language experiments are temporary features that are added, removed, and/or concluded at cadences too unpredictable to be included in this completion list. These are used in alpha or beta builds of Terraform and are changed frequently enough that it would either always be out of date or require constant releases to keep up to date. As such, the completion list for the `experiments` attribute has been removed and documentation added to instruct the user to look to documentation for the particular release they are using for a list of features that can be enabled. --- internal/schema/0.14/terraform.go | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/internal/schema/0.14/terraform.go b/internal/schema/0.14/terraform.go index 771466a7..f3546e33 100644 --- a/internal/schema/0.14/terraform.go +++ b/internal/schema/0.14/terraform.go @@ -26,20 +26,10 @@ func terraformBlockSchema(v *version.Version) *schema.BlockSchema { "with this configuration, e.g. `~> 0.12`"), }, "experiments": { - Constraint: schema.Set{ - Elem: schema.OneOf{ - schema.Keyword{ - Keyword: "module_variable_optional_attrs", - Name: "feature", - }, - schema.Keyword{ - Keyword: "provider_sensitive_attrs", - Name: "feature", - }, - }, - }, - IsOptional: true, - Description: lang.Markdown("A set of experimental language features to enable"), + Constraint: schema.LiteralType{Type: cty.String}, + IsOptional: true, + Description: lang.Markdown("A set of experimental language features to enable. Consult the documentation" + + " for the version of Terraform you arte using for a list of available experiments"), }, }, Blocks: map[string]*schema.BlockSchema{ From f009886eb477ea93cea8a743783d18e447ab4830 Mon Sep 17 00:00:00 2001 From: James Pogran Date: Wed, 3 Apr 2024 10:38:26 -0400 Subject: [PATCH 2/3] Update internal/schema/0.14/terraform.go Co-authored-by: Ansgar Mertens --- internal/schema/0.14/terraform.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/schema/0.14/terraform.go b/internal/schema/0.14/terraform.go index f3546e33..931663bd 100644 --- a/internal/schema/0.14/terraform.go +++ b/internal/schema/0.14/terraform.go @@ -29,7 +29,7 @@ func terraformBlockSchema(v *version.Version) *schema.BlockSchema { Constraint: schema.LiteralType{Type: cty.String}, IsOptional: true, Description: lang.Markdown("A set of experimental language features to enable. Consult the documentation" + - " for the version of Terraform you arte using for a list of available experiments"), + " for the version of Terraform you are using for a list of available experiments"), }, }, Blocks: map[string]*schema.BlockSchema{ From 704904667dab54d460c51b85c6000efc0f5e4be7 Mon Sep 17 00:00:00 2001 From: Ansgar Mertens Date: Wed, 10 Apr 2024 10:11:04 +0200 Subject: [PATCH 3/3] conclude module_variable_optional_attrs experiment in new TF 1.8 schema --- internal/schema/0.14/terraform.go | 18 ++++++++++++++---- internal/schema/1.8/root.go | 17 +++++++++++++++++ internal/schema/1.8/terraform.go | 27 +++++++++++++++++++++++++++ schema/core_schema.go | 5 +++++ 4 files changed, 63 insertions(+), 4 deletions(-) create mode 100644 internal/schema/1.8/root.go create mode 100644 internal/schema/1.8/terraform.go diff --git a/internal/schema/0.14/terraform.go b/internal/schema/0.14/terraform.go index 931663bd..771466a7 100644 --- a/internal/schema/0.14/terraform.go +++ b/internal/schema/0.14/terraform.go @@ -26,10 +26,20 @@ func terraformBlockSchema(v *version.Version) *schema.BlockSchema { "with this configuration, e.g. `~> 0.12`"), }, "experiments": { - Constraint: schema.LiteralType{Type: cty.String}, - IsOptional: true, - Description: lang.Markdown("A set of experimental language features to enable. Consult the documentation" + - " for the version of Terraform you are using for a list of available experiments"), + Constraint: schema.Set{ + Elem: schema.OneOf{ + schema.Keyword{ + Keyword: "module_variable_optional_attrs", + Name: "feature", + }, + schema.Keyword{ + Keyword: "provider_sensitive_attrs", + Name: "feature", + }, + }, + }, + IsOptional: true, + Description: lang.Markdown("A set of experimental language features to enable"), }, }, Blocks: map[string]*schema.BlockSchema{ diff --git a/internal/schema/1.8/root.go b/internal/schema/1.8/root.go new file mode 100644 index 00000000..6d0cb5d5 --- /dev/null +++ b/internal/schema/1.8/root.go @@ -0,0 +1,17 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package schema + +import ( + "github.com/hashicorp/go-version" + "github.com/hashicorp/hcl-lang/schema" + + v1_7_mod "github.com/hashicorp/terraform-schema/internal/schema/1.7" +) + +func ModuleSchema(v *version.Version) *schema.BodySchema { + bs := v1_7_mod.ModuleSchema(v) + bs.Blocks["terraform"] = patchTerraformBlockSchema(bs.Blocks["terraform"]) + return bs +} diff --git a/internal/schema/1.8/terraform.go b/internal/schema/1.8/terraform.go new file mode 100644 index 00000000..2089d198 --- /dev/null +++ b/internal/schema/1.8/terraform.go @@ -0,0 +1,27 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package schema + +import ( + "github.com/hashicorp/hcl-lang/lang" + "github.com/hashicorp/hcl-lang/schema" +) + +func patchTerraformBlockSchema(bs *schema.BlockSchema) *schema.BlockSchema { + // removes module_variable_optional_attrs experiment (defined in 0.14) + bs.Body.Attributes["experiments"] = &schema.AttributeSchema{ + Constraint: schema.Set{ + Elem: schema.OneOf{ + schema.Keyword{ + Keyword: "provider_sensitive_attrs", + Name: "feature", + }, + }, + }, + IsOptional: true, + Description: lang.Markdown("A set of experimental language features to enable"), + } + + return bs +} diff --git a/schema/core_schema.go b/schema/core_schema.go index fc2afd48..2e87cbc1 100644 --- a/schema/core_schema.go +++ b/schema/core_schema.go @@ -16,6 +16,7 @@ import ( mod_v1_5 "github.com/hashicorp/terraform-schema/internal/schema/1.5" mod_v1_6 "github.com/hashicorp/terraform-schema/internal/schema/1.6" mod_v1_7 "github.com/hashicorp/terraform-schema/internal/schema/1.7" + mod_v1_8 "github.com/hashicorp/terraform-schema/internal/schema/1.8" ) var ( @@ -30,6 +31,7 @@ var ( v1_5 = version.Must(version.NewVersion("1.5")) v1_6 = version.Must(version.NewVersion("1.6")) v1_7 = version.Must(version.NewVersion("1.7")) + v1_8 = version.Must(version.NewVersion("1.8")) ) // CoreModuleSchemaForVersion finds a module schema which is relevant @@ -37,6 +39,9 @@ var ( // It will return error if such schema cannot be found. func CoreModuleSchemaForVersion(v *version.Version) (*schema.BodySchema, error) { ver := v.Core() + if ver.GreaterThanOrEqual(v1_8) { + return mod_v1_8.ModuleSchema(ver), nil + } if ver.GreaterThanOrEqual(v1_7) { return mod_v1_7.ModuleSchema(ver), nil }