Skip to content

Commit 3a2c18d

Browse files
authored
Correct the prebuilds type (#376)
1 parent ef92eea commit 3a2c18d

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

provider/workspace_preset.go

+8-13
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ import (
1212
type WorkspacePreset struct {
1313
Name string `mapstructure:"name"`
1414
Parameters map[string]string `mapstructure:"parameters"`
15-
Prebuilds WorkspacePrebuild `mapstructure:"prebuilds"`
15+
// There should always be only one prebuild block, but Terraform's type system
16+
// still parses them as a slice, so we need to handle it as such. We could use
17+
// an anonymous type and rd.Get to avoid a slice here, but that would not be possible
18+
// for utilities that parse our terraform output using this type. To remain compatible
19+
// with those cases, we use a slice here.
20+
Prebuilds []WorkspacePrebuild `mapstructure:"prebuilds"`
1621
}
1722

1823
type WorkspacePrebuild struct {
@@ -27,19 +32,9 @@ func workspacePresetDataSource() *schema.Resource {
2732
ReadContext: func(ctx context.Context, rd *schema.ResourceData, i interface{}) diag.Diagnostics {
2833
var preset WorkspacePreset
2934
err := mapstructure.Decode(struct {
30-
Name interface{}
31-
Parameters interface{}
32-
Prebuilds struct {
33-
Instances interface{}
34-
}
35+
Name interface{}
3536
}{
36-
Name: rd.Get("name"),
37-
Parameters: rd.Get("parameters"),
38-
Prebuilds: struct {
39-
Instances interface{}
40-
}{
41-
Instances: rd.Get("prebuilds.0.instances"),
42-
},
37+
Name: rd.Get("name"),
4338
}, &preset)
4439
if err != nil {
4540
return diag.Errorf("decode workspace preset: %s", err)

0 commit comments

Comments
 (0)