Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

schema: Add v1.4 local-exec provisioner quiet attribute #218

Merged
merged 1 commit into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion schema/core_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func TestCoreModuleSchemaForConstraint(t *testing.T) {
},
{
version.Constraints{},
mod_v1_2.ModuleSchema(version.Must(version.NewVersion("1.3.0"))),
mod_v1_2.ModuleSchema(version.Must(version.NewVersion("1.4.0"))),
nil,
},
{
Expand Down