Skip to content

Commit

Permalink
schema: Add v1.4 local-exec provisioner quiet attribute (#218)
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko committed May 22, 2023
1 parent 3d07383 commit 934122b
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 3 deletions.
12 changes: 9 additions & 3 deletions internal/schema/0.15/provisioners.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,19 @@ import (
v014_mod "github.com/hashicorp/terraform-schema/internal/schema/0.14"
)

var (
FileProvisioner = v014_mod.FileProvisioner
LocalExecProvisioner = v014_mod.LocalExecProvisioner
RemoteExecProvisioner = v014_mod.RemoteExecProvisioner
)

// See https://github.com/hashicorp/terraform/tree/v0.15.0/builtin/provisioners

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

Expand Down
42 changes: 42 additions & 0 deletions internal/schema/1.4/provisioners.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

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"

v0_15_mod "github.com/hashicorp/terraform-schema/internal/schema/0.15"
)

var (
FileProvisioner = v0_15_mod.FileProvisioner
LocalExecProvisioner = func() *schema.BodySchema {
// See https: //github.com/hashicorp/terraform/pull/32116/files
bodySchema := v0_15_mod.LocalExecProvisioner
bodySchema.Attributes["quiet"] = &schema.AttributeSchema{
Constraint: schema.LiteralType{Type: cty.Bool},
IsOptional: true,
Description: lang.Markdown("Whether to suppress script output"),
}
return bodySchema
}()
RemoteExecProvisioner = v0_15_mod.RemoteExecProvisioner
)

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,
}
}

func labelKey(value string) schema.SchemaKey {
return schema.NewSchemaKey(schema.DependencyKeys{
Labels: []schema.LabelDependent{{Index: 0, Value: value}},
})
}
18 changes: 18 additions & 0 deletions internal/schema/1.4/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 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_2_mod "github.com/hashicorp/terraform-schema/internal/schema/1.2"
)

func ModuleSchema(v *version.Version) *schema.BodySchema {
bs := v1_2_mod.ModuleSchema(v)
bs.Blocks["resource"].Body.Blocks["provisioner"].DependentBody = ProvisionerDependentBodies(v)

return bs
}
4 changes: 4 additions & 0 deletions schema/core_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
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_2 "github.com/hashicorp/terraform-schema/internal/schema/1.2"
mod_v1_4 "github.com/hashicorp/terraform-schema/internal/schema/1.4"
)

var (
Expand All @@ -30,6 +31,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_4) {
return mod_v1_4.ModuleSchema(ver), nil
}
if ver.GreaterThanOrEqual(v1_2) {
return mod_v1_2.ModuleSchema(ver), nil
}
Expand Down

0 comments on commit 934122b

Please sign in to comment.