Skip to content

Commit

Permalink
Add 1.7 removed block
Browse files Browse the repository at this point in the history
  • Loading branch information
dbanck committed Jan 12, 2024
1 parent 4074cb2 commit 299dae6
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
43 changes: 43 additions & 0 deletions internal/schema/1.7/removed.go
Original file line number Diff line number Diff line change
@@ -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,
},
},
},
}
}
17 changes: 17 additions & 0 deletions internal/schema/1.7/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_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
}
5 changes: 5 additions & 0 deletions schema/core_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -28,13 +29,17 @@ 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
// 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_7) {
return mod_v1_7.ModuleSchema(ver), nil
}
if ver.GreaterThanOrEqual(v1_6) {
return mod_v1_6.ModuleSchema(ver), nil
}
Expand Down

0 comments on commit 299dae6

Please sign in to comment.