@@ -2,16 +2,20 @@ package provider
2
2
3
3
import (
4
4
"context"
5
-
6
5
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
7
6
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
8
7
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
9
8
"github.com/mitchellh/mapstructure"
10
9
)
11
10
12
11
type WorkspacePreset struct {
13
- Name string `mapstructure:"name"`
14
- Parameters map [string ]string `mapstructure:"parameters"`
12
+ Name string `mapstructure:"name"`
13
+ Parameters map [string ]string `mapstructure:"parameters"`
14
+ Prebuild []WorkspacePrebuild `mapstructure:"prebuilds"`
15
+ }
16
+
17
+ type WorkspacePrebuild struct {
18
+ Instances int `mapstructure:"instances"`
15
19
}
16
20
17
21
func workspacePresetDataSource () * schema.Resource {
@@ -24,9 +28,19 @@ func workspacePresetDataSource() *schema.Resource {
24
28
err := mapstructure .Decode (struct {
25
29
Name interface {}
26
30
Parameters interface {}
31
+ Prebuilds []struct {
32
+ Instances interface {}
33
+ }
27
34
}{
28
35
Name : rd .Get ("name" ),
29
36
Parameters : rd .Get ("parameters" ),
37
+ Prebuilds : []struct {
38
+ Instances interface {}
39
+ }{
40
+ {
41
+ Instances : rd .Get ("prebuilds.0.instances" ),
42
+ },
43
+ },
30
44
}, & preset )
31
45
if err != nil {
32
46
return diag .Errorf ("decode workspace preset: %s" , err )
@@ -65,6 +79,22 @@ func workspacePresetDataSource() *schema.Resource {
65
79
ValidateFunc : validation .StringIsNotEmpty ,
66
80
},
67
81
},
82
+ "prebuilds" : {
83
+ Type : schema .TypeSet ,
84
+ Description : "Prebuilds of the workspace preset." ,
85
+ Optional : true ,
86
+ MaxItems : 1 , // TODO: is this always true? More than 1 prebuilds config per preset?
87
+ Elem : & schema.Resource {
88
+ Schema : map [string ]* schema.Schema {
89
+ "instances" : {
90
+ Type : schema .TypeInt ,
91
+ Required : true ,
92
+ ForceNew : true ,
93
+ ValidateFunc : validation .IntAtLeast (1 ),
94
+ },
95
+ },
96
+ },
97
+ },
68
98
},
69
99
}
70
100
}
0 commit comments