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

WIP: schema additions for ephemeral values #394

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
27 changes: 27 additions & 0 deletions internal/schema/1.10/root.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/go-version"
"github.com/hashicorp/hcl-lang/schema"
"github.com/zclconf/go-cty/cty"

v1_9_mod "github.com/hashicorp/terraform-schema/internal/schema/1.9"
)

func ModuleSchema(v *version.Version) *schema.BodySchema {
bs := v1_9_mod.ModuleSchema(v)

bs.Blocks["variable"].Body.Attributes["ephemeral"] = &schema.AttributeSchema{
IsOptional: true,
Constraint: schema.LiteralType{Type: cty.Bool},
}
bs.Blocks["output"].Body.Attributes["ephemeral"] = &schema.AttributeSchema{
IsOptional: true,
Constraint: schema.LiteralType{Type: cty.Bool},
}

return bs
}
5 changes: 5 additions & 0 deletions schema/core_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
mod_v0_14 "github.com/hashicorp/terraform-schema/internal/schema/0.14"
mod_v0_15 "github.com/hashicorp/terraform-schema/internal/schema/0.15"
mod_v1_1 "github.com/hashicorp/terraform-schema/internal/schema/1.1"
mod_v1_10 "github.com/hashicorp/terraform-schema/internal/schema/1.10"
mod_v1_2 "github.com/hashicorp/terraform-schema/internal/schema/1.2"
mod_v1_4 "github.com/hashicorp/terraform-schema/internal/schema/1.4"
mod_v1_5 "github.com/hashicorp/terraform-schema/internal/schema/1.5"
Expand All @@ -34,13 +35,17 @@ var (
v1_7 = version.Must(version.NewVersion("1.7"))
v1_8 = version.Must(version.NewVersion("1.8"))
v1_9 = version.Must(version.NewVersion("1.9"))
v1_10 = version.Must(version.NewVersion("1.10"))
)

// 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_10) {
return mod_v1_10.ModuleSchema(ver), nil
}
if ver.GreaterThanOrEqual(v1_9) {
return mod_v1_9.ModuleSchema(ver), nil
}
Expand Down