Skip to content

Commit

Permalink
cleanup: avoid passing version where it's not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko committed Aug 4, 2022
1 parent e6ed356 commit 2d308dd
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 24 deletions.
28 changes: 13 additions & 15 deletions internal/schema/0.14/provisioners.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,19 @@ func ConnectionDependentBodies(v *version.Version) map[schema.SchemaKey]*schema.
return v013_mod.ConnectionDependentBodies(v)
}

func ProvisionerDependentBodies(v *version.Version) map[schema.SchemaKey]*schema.BodySchema {
return map[schema.SchemaKey]*schema.BodySchema{
labelKey("file"): FileProvisioner,
labelKey("local-exec"): LocalExecProvisioner,
labelKey("remote-exec"): RemoteExecProvisioner,

// Vendor provisioners are deprecated in 0.13.4+
// See https://discuss.hashicorp.com/t/notice-terraform-to-begin-deprecation-of-vendor-tool-specific-provisioners-starting-in-terraform-0-13-4/13997
// Some of these provisioners have complex schemas
// but we can at least helpfully list their names
labelKey("chef"): {IsDeprecated: true},
labelKey("salt-masterless"): {IsDeprecated: true},
labelKey("habitat"): {IsDeprecated: true},
labelKey("puppet"): {IsDeprecated: true},
}
var ProvisionerDependentBodies = map[schema.SchemaKey]*schema.BodySchema{
labelKey("file"): FileProvisioner,
labelKey("local-exec"): LocalExecProvisioner,
labelKey("remote-exec"): RemoteExecProvisioner,

// Vendor provisioners are deprecated in 0.13.4+
// See https://discuss.hashicorp.com/t/notice-terraform-to-begin-deprecation-of-vendor-tool-specific-provisioners-starting-in-terraform-0-13-4/13997
// Some of these provisioners have complex schemas
// but we can at least helpfully list their names
labelKey("chef"): {IsDeprecated: true},
labelKey("salt-masterless"): {IsDeprecated: true},
labelKey("habitat"): {IsDeprecated: true},
labelKey("puppet"): {IsDeprecated: true},
}

func labelKey(value string) schema.SchemaKey {
Expand Down
2 changes: 1 addition & 1 deletion internal/schema/0.14/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func ModuleSchema(v *version.Version) *schema.BodySchema {

bs.Blocks["variable"] = variableBlockSchema
bs.Blocks["terraform"] = terraformBlockSchema(v)
bs.Blocks["resource"].Body.Blocks["provisioner"].DependentBody = ProvisionerDependentBodies(v)
bs.Blocks["resource"].Body.Blocks["provisioner"].DependentBody = ProvisionerDependentBodies

return bs
}
2 changes: 1 addition & 1 deletion internal/schema/0.15/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

func ModuleSchema(v *version.Version) *schema.BodySchema {
bs := v014_mod.ModuleSchema(v)
bs.Blocks["terraform"] = patchTerraformBlockSchema(bs.Blocks["terraform"], v)
bs.Blocks["terraform"] = patchTerraformBlockSchema(bs.Blocks["terraform"])
bs.Blocks["resource"].Body.Blocks["provisioner"].DependentBody = ProvisionerDependentBodies(v)
bs.Blocks["resource"].Body.Blocks["connection"].DependentBody = ConnectionDependentBodies(v)

Expand Down
3 changes: 1 addition & 2 deletions internal/schema/0.15/terraform.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package schema

import (
"github.com/hashicorp/go-version"
"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 patchTerraformBlockSchema(bs *schema.BlockSchema, v *version.Version) *schema.BlockSchema {
func patchTerraformBlockSchema(bs *schema.BlockSchema) *schema.BlockSchema {
bs.Body.Blocks["required_providers"].Body = &schema.BodySchema{
AnyAttribute: &schema.AttributeSchema{
Expr: schema.ExprConstraints{
Expand Down
2 changes: 1 addition & 1 deletion internal/schema/1.1/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ import (
func ModuleSchema(v *version.Version) *schema.BodySchema {
bs := v015_mod.ModuleSchema(v)
bs.Blocks["moved"] = movedBlockSchema
bs.Blocks["terraform"] = patchTerraformBlockSchema(bs.Blocks["terraform"], v)
bs.Blocks["terraform"] = patchTerraformBlockSchema(bs.Blocks["terraform"])
return bs
}
3 changes: 1 addition & 2 deletions internal/schema/1.1/terraform.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
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"
)

func patchTerraformBlockSchema(bs *schema.BlockSchema, v *version.Version) *schema.BlockSchema {
func patchTerraformBlockSchema(bs *schema.BlockSchema) *schema.BlockSchema {
bs.Body.Blocks["cloud"] = &schema.BlockSchema{
Description: lang.PlainText("Terraform Cloud configuration"),
MaxItems: 1,
Expand Down
2 changes: 0 additions & 2 deletions internal/schema/1.2/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
v1_1_mod "github.com/hashicorp/terraform-schema/internal/schema/1.1"
)

var v1_2 = version.Must(version.NewVersion("1.2.0"))

func ModuleSchema(v *version.Version) *schema.BodySchema {
bs := v1_1_mod.ModuleSchema(v)
bs.Blocks["data"].Body.Blocks = map[string]*schema.BlockSchema{
Expand Down

0 comments on commit 2d308dd

Please sign in to comment.