From fc9b9053817dea0db5ca78d5c556a51c26acbbbc Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Wed, 21 Aug 2024 15:13:11 +0100 Subject: [PATCH 1/3] schema additions for ephemeral values --- internal/schema/1.10/root.go | 27 +++++++++++++++++++++++++++ schema/core_schema.go | 5 +++++ 2 files changed, 32 insertions(+) create mode 100644 internal/schema/1.10/root.go diff --git a/internal/schema/1.10/root.go b/internal/schema/1.10/root.go new file mode 100644 index 00000000..68df6e0d --- /dev/null +++ b/internal/schema/1.10/root.go @@ -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 +} diff --git a/schema/core_schema.go b/schema/core_schema.go index 0fb07fed..0711a39b 100644 --- a/schema/core_schema.go +++ b/schema/core_schema.go @@ -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" @@ -34,6 +35,7 @@ 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 @@ -41,6 +43,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_10) { + return mod_v1_10.ModuleSchema(ver), nil + } if ver.GreaterThanOrEqual(v1_9) { return mod_v1_9.ModuleSchema(ver), nil } From 169c9f11b5c7884ed7db7dc70d83bdfafb28e19f Mon Sep 17 00:00:00 2001 From: Ansgar Mertens Date: Fri, 11 Oct 2024 15:20:07 +0200 Subject: [PATCH 2/3] add description for ephemeral attribute, also add it to stack outputs --- internal/schema/1.10/root.go | 11 +++++++---- internal/schema/stacks/1.9/output_block.go | 5 +++++ internal/schema/stacks/1.9/variable_block.go | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/internal/schema/1.10/root.go b/internal/schema/1.10/root.go index 68df6e0d..305245a9 100644 --- a/internal/schema/1.10/root.go +++ b/internal/schema/1.10/root.go @@ -5,6 +5,7 @@ package schema import ( "github.com/hashicorp/go-version" + "github.com/hashicorp/hcl-lang/lang" "github.com/hashicorp/hcl-lang/schema" "github.com/zclconf/go-cty/cty" @@ -15,12 +16,14 @@ 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}, + IsOptional: true, + Constraint: schema.LiteralType{Type: cty.Bool}, + Description: lang.PlainText("Whether the value is ephemeral and should not be persisted in the state"), } bs.Blocks["output"].Body.Attributes["ephemeral"] = &schema.AttributeSchema{ - IsOptional: true, - Constraint: schema.LiteralType{Type: cty.Bool}, + IsOptional: true, + Constraint: schema.LiteralType{Type: cty.Bool}, + Description: lang.PlainText("Whether the value is ephemeral and should not be persisted in the state"), } return bs diff --git a/internal/schema/stacks/1.9/output_block.go b/internal/schema/stacks/1.9/output_block.go index d74209d9..9e7164f4 100644 --- a/internal/schema/stacks/1.9/output_block.go +++ b/internal/schema/stacks/1.9/output_block.go @@ -48,6 +48,11 @@ func outputBlockSchema() *schema.BlockSchema { IsRequired: true, Description: lang.PlainText("Type of the output value"), }, + "ephemeral": { + Constraint: schema.LiteralType{Type: cty.Bool}, + IsOptional: true, + Description: lang.PlainText("Whether the value is ephemeral and should not be persisted in the state"), + }, }, }, } diff --git a/internal/schema/stacks/1.9/variable_block.go b/internal/schema/stacks/1.9/variable_block.go index 70797b21..59ce8e1c 100644 --- a/internal/schema/stacks/1.9/variable_block.go +++ b/internal/schema/stacks/1.9/variable_block.go @@ -51,7 +51,7 @@ func variableBlockSchema() *schema.BlockSchema { "ephemeral": { Constraint: schema.LiteralType{Type: cty.Bool}, IsOptional: true, - Description: lang.Markdown("Ephemeral values are not saved in the state file and are not visible in the UI"), + Description: lang.PlainText("Whether the value is ephemeral and should not be persisted in the state"), }, "type": { Constraint: schema.TypeDeclaration{}, From b5a0258818ffa8604129e644bbec2ad1ac8e66ee Mon Sep 17 00:00:00 2001 From: Ansgar Mertens Date: Tue, 15 Oct 2024 14:22:10 +0200 Subject: [PATCH 3/3] add sensitive to Stack outputs --- internal/schema/stacks/1.9/output_block.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/internal/schema/stacks/1.9/output_block.go b/internal/schema/stacks/1.9/output_block.go index 9e7164f4..40d0b6c3 100644 --- a/internal/schema/stacks/1.9/output_block.go +++ b/internal/schema/stacks/1.9/output_block.go @@ -48,6 +48,12 @@ func outputBlockSchema() *schema.BlockSchema { IsRequired: true, Description: lang.PlainText("Type of the output value"), }, + "sensitive": { + Constraint: schema.LiteralType{Type: cty.Bool}, + DefaultValue: schema.DefaultValue{Value: cty.False}, + IsOptional: true, + Description: lang.Markdown("Whether the output contains sensitive material and should be hidden in the UI"), + }, "ephemeral": { Constraint: schema.LiteralType{Type: cty.Bool}, IsOptional: true,