From 299dae65b1c3ab171d56620b7275da35c5a4d4f0 Mon Sep 17 00:00:00 2001 From: Daniel Banck Date: Fri, 12 Jan 2024 12:35:12 +0100 Subject: [PATCH] Add 1.7 removed block --- internal/schema/1.7/removed.go | 43 ++++++++++++++++++++++++++++++++++ internal/schema/1.7/root.go | 17 ++++++++++++++ schema/core_schema.go | 5 ++++ 3 files changed, 65 insertions(+) create mode 100644 internal/schema/1.7/removed.go create mode 100644 internal/schema/1.7/root.go diff --git a/internal/schema/1.7/removed.go b/internal/schema/1.7/removed.go new file mode 100644 index 00000000..8b53c2c8 --- /dev/null +++ b/internal/schema/1.7/removed.go @@ -0,0 +1,43 @@ +// 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" + "github.com/hashicorp/terraform-schema/internal/schema/refscope" + "github.com/zclconf/go-cty/cty" +) + +func removedBlock() *schema.BlockSchema { + return &schema.BlockSchema{ + Description: lang.Markdown("Declaration to specify what address to remove from the state"), + Body: &schema.BodySchema{ + Attributes: map[string]*schema.AttributeSchema{ + "from": { + Constraint: schema.OneOf{ + schema.Reference{OfScopeId: refscope.ModuleScope}, + schema.Reference{OfScopeId: refscope.ResourceScope}, + }, + IsRequired: true, + Description: lang.Markdown("Address of the module or resource to be removed"), + }, + }, + Blocks: map[string]*schema.BlockSchema{ + "lifecycle": { + Body: &schema.BodySchema{ + Attributes: map[string]*schema.AttributeSchema{ + "destroy": { + Constraint: schema.LiteralType{Type: cty.Bool}, + IsRequired: true, + }, + }, + }, + MinItems: 1, + MaxItems: 1, + }, + }, + }, + } +} diff --git a/internal/schema/1.7/root.go b/internal/schema/1.7/root.go new file mode 100644 index 00000000..25553cb6 --- /dev/null +++ b/internal/schema/1.7/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_6_mod "github.com/hashicorp/terraform-schema/internal/schema/1.6" +) + +func ModuleSchema(v *version.Version) *schema.BodySchema { + bs := v1_6_mod.ModuleSchema(v) + bs.Blocks["removed"] = removedBlock() + return bs +} diff --git a/schema/core_schema.go b/schema/core_schema.go index 08baac01..fc2afd48 100644 --- a/schema/core_schema.go +++ b/schema/core_schema.go @@ -15,6 +15,7 @@ import ( mod_v1_4 "github.com/hashicorp/terraform-schema/internal/schema/1.4" 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" ) var ( @@ -28,6 +29,7 @@ var ( v1_4 = version.Must(version.NewVersion("1.4")) v1_5 = version.Must(version.NewVersion("1.5")) v1_6 = version.Must(version.NewVersion("1.6")) + v1_7 = version.Must(version.NewVersion("1.7")) ) // CoreModuleSchemaForVersion finds a module schema which is relevant @@ -35,6 +37,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_7) { + return mod_v1_7.ModuleSchema(ver), nil + } if ver.GreaterThanOrEqual(v1_6) { return mod_v1_6.ModuleSchema(ver), nil }