Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conclude Terraform Experiments Completion #337

Merged
merged 3 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions internal/schema/1.8/root.go
Original file line number Diff line number Diff line change
@@ -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
}
27 changes: 27 additions & 0 deletions internal/schema/1.8/terraform.go
Original file line number Diff line number Diff line change
@@ -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
}
5 changes: 5 additions & 0 deletions schema/core_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -30,13 +31,17 @@ 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
// for the given Terraform version.
// 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
}
Expand Down
Loading