Skip to content

Commit

Permalink
Add removed block (v1.7) (#313)
Browse files Browse the repository at this point in the history
* Regenerate Terraform versions

Including 1.7

* Add 1.7 removed block

* Apply suggestions from code review

Co-authored-by: Radek Simko <radek.simko@gmail.com>

* Fix typos

---------

Co-authored-by: Radek Simko <radek.simko@gmail.com>
  • Loading branch information
dbanck and radeksimko authored Jan 12, 2024
1 parent 6171611 commit 8d880b4
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 1 deletion.
46 changes: 46 additions & 0 deletions internal/schema/1.7/removed.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// 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 resource or module to remove from the state"),
Body: &schema.BodySchema{
HoverURL: "https://developer.hashicorp.com/terraform/language/resources/syntax#removing-resources",
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": {
Description: lang.Markdown("Lifecycle customizations controlling the removal"),
Body: &schema.BodySchema{
Attributes: map[string]*schema.AttributeSchema{
"destroy": {
Constraint: schema.LiteralType{Type: cty.Bool},
IsRequired: true,
Description: lang.Markdown("Whether Terraform will attempt to destroy the objects (`true`) or not, i.e. just remove from state (`false`)."),
},
},
},
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
10 changes: 9 additions & 1 deletion schema/versions_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8d880b4

Please sign in to comment.