Skip to content

Commit 934122b

Browse files
authored
schema: Add v1.4 local-exec provisioner quiet attribute (#218)
1 parent 3d07383 commit 934122b

File tree

4 files changed

+73
-3
lines changed

4 files changed

+73
-3
lines changed

internal/schema/0.15/provisioners.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,19 @@ import (
1010
v014_mod "github.com/hashicorp/terraform-schema/internal/schema/0.14"
1111
)
1212

13+
var (
14+
FileProvisioner = v014_mod.FileProvisioner
15+
LocalExecProvisioner = v014_mod.LocalExecProvisioner
16+
RemoteExecProvisioner = v014_mod.RemoteExecProvisioner
17+
)
18+
1319
// See https://github.com/hashicorp/terraform/tree/v0.15.0/builtin/provisioners
1420

1521
func ProvisionerDependentBodies(v *version.Version) map[schema.SchemaKey]*schema.BodySchema {
1622
return map[schema.SchemaKey]*schema.BodySchema{
17-
labelKey("file"): v014_mod.FileProvisioner,
18-
labelKey("local-exec"): v014_mod.LocalExecProvisioner,
19-
labelKey("remote-exec"): v014_mod.RemoteExecProvisioner,
23+
labelKey("file"): FileProvisioner,
24+
labelKey("local-exec"): LocalExecProvisioner,
25+
labelKey("remote-exec"): RemoteExecProvisioner,
2026
}
2127
}
2228

internal/schema/1.4/provisioners.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package schema
5+
6+
import (
7+
"github.com/hashicorp/go-version"
8+
"github.com/hashicorp/hcl-lang/lang"
9+
"github.com/hashicorp/hcl-lang/schema"
10+
"github.com/zclconf/go-cty/cty"
11+
12+
v0_15_mod "github.com/hashicorp/terraform-schema/internal/schema/0.15"
13+
)
14+
15+
var (
16+
FileProvisioner = v0_15_mod.FileProvisioner
17+
LocalExecProvisioner = func() *schema.BodySchema {
18+
// See https: //github.com/hashicorp/terraform/pull/32116/files
19+
bodySchema := v0_15_mod.LocalExecProvisioner
20+
bodySchema.Attributes["quiet"] = &schema.AttributeSchema{
21+
Constraint: schema.LiteralType{Type: cty.Bool},
22+
IsOptional: true,
23+
Description: lang.Markdown("Whether to suppress script output"),
24+
}
25+
return bodySchema
26+
}()
27+
RemoteExecProvisioner = v0_15_mod.RemoteExecProvisioner
28+
)
29+
30+
func ProvisionerDependentBodies(v *version.Version) map[schema.SchemaKey]*schema.BodySchema {
31+
return map[schema.SchemaKey]*schema.BodySchema{
32+
labelKey("file"): FileProvisioner,
33+
labelKey("local-exec"): LocalExecProvisioner,
34+
labelKey("remote-exec"): RemoteExecProvisioner,
35+
}
36+
}
37+
38+
func labelKey(value string) schema.SchemaKey {
39+
return schema.NewSchemaKey(schema.DependencyKeys{
40+
Labels: []schema.LabelDependent{{Index: 0, Value: value}},
41+
})
42+
}

internal/schema/1.4/root.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package schema
5+
6+
import (
7+
"github.com/hashicorp/go-version"
8+
"github.com/hashicorp/hcl-lang/schema"
9+
10+
v1_2_mod "github.com/hashicorp/terraform-schema/internal/schema/1.2"
11+
)
12+
13+
func ModuleSchema(v *version.Version) *schema.BodySchema {
14+
bs := v1_2_mod.ModuleSchema(v)
15+
bs.Blocks["resource"].Body.Blocks["provisioner"].DependentBody = ProvisionerDependentBodies(v)
16+
17+
return bs
18+
}

schema/core_schema.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
mod_v0_15 "github.com/hashicorp/terraform-schema/internal/schema/0.15"
1313
mod_v1_1 "github.com/hashicorp/terraform-schema/internal/schema/1.1"
1414
mod_v1_2 "github.com/hashicorp/terraform-schema/internal/schema/1.2"
15+
mod_v1_4 "github.com/hashicorp/terraform-schema/internal/schema/1.4"
1516
)
1617

1718
var (
@@ -30,6 +31,9 @@ var (
3031
// It will return error if such schema cannot be found.
3132
func CoreModuleSchemaForVersion(v *version.Version) (*schema.BodySchema, error) {
3233
ver := v.Core()
34+
if ver.GreaterThanOrEqual(v1_4) {
35+
return mod_v1_4.ModuleSchema(ver), nil
36+
}
3337
if ver.GreaterThanOrEqual(v1_2) {
3438
return mod_v1_2.ModuleSchema(ver), nil
3539
}

0 commit comments

Comments
 (0)