@@ -2,16 +2,20 @@ package provider
22
33import (
44 "context"
5-
65 "github.com/hashicorp/terraform-plugin-sdk/v2/diag"
76 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
87 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
98 "github.com/mitchellh/mapstructure"
109)
1110
1211type 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"`
1519}
1620
1721func workspacePresetDataSource () * schema.Resource {
@@ -24,9 +28,19 @@ func workspacePresetDataSource() *schema.Resource {
2428 err := mapstructure .Decode (struct {
2529 Name interface {}
2630 Parameters interface {}
31+ Prebuilds []struct {
32+ Instances interface {}
33+ }
2734 }{
2835 Name : rd .Get ("name" ),
2936 Parameters : rd .Get ("parameters" ),
37+ Prebuilds : []struct {
38+ Instances interface {}
39+ }{
40+ {
41+ Instances : rd .Get ("prebuilds.0.instances" ),
42+ },
43+ },
3044 }, & preset )
3145 if err != nil {
3246 return diag .Errorf ("decode workspace preset: %s" , err )
@@ -65,6 +79,22 @@ func workspacePresetDataSource() *schema.Resource {
6579 ValidateFunc : validation .StringIsNotEmpty ,
6680 },
6781 },
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+ },
6898 },
6999 }
70100}
0 commit comments