File tree Expand file tree Collapse file tree 3 files changed +76
-6
lines changed Expand file tree Collapse file tree 3 files changed +76
-6
lines changed Original file line number Diff line number Diff line change @@ -61,12 +61,13 @@ func New() *schema.Provider {
6161 }, nil
6262 },
6363 DataSourcesMap : map [string ]* schema.Resource {
64- "coder_workspace" : workspaceDataSource (),
65- "coder_workspace_tags" : workspaceTagDataSource (),
66- "coder_provisioner" : provisionerDataSource (),
67- "coder_parameter" : parameterDataSource (),
68- "coder_external_auth" : externalAuthDataSource (),
69- "coder_workspace_owner" : workspaceOwnerDataSource (),
64+ "coder_workspace" : workspaceDataSource (),
65+ "coder_workspace_tags" : workspaceTagDataSource (),
66+ "coder_provisioner" : provisionerDataSource (),
67+ "coder_parameter" : parameterDataSource (),
68+ "coder_external_auth" : externalAuthDataSource (),
69+ "coder_workspace_owner" : workspaceOwnerDataSource (),
70+ "coder_workspace_preset" : workspacePresetDataSource (),
7071 },
7172 ResourcesMap : map [string ]* schema.Resource {
7273 "coder_agent" : agentResource (),
Original file line number Diff line number Diff line change 1+ package provider
2+
3+ import (
4+ "context"
5+
6+ "github.com/google/uuid"
7+ "github.com/hashicorp/terraform-plugin-sdk/v2/diag"
8+ "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
9+ )
10+
11+ func workspacePresetDataSource () * schema.Resource {
12+ return & schema.Resource {
13+ SchemaVersion : 1 ,
14+
15+ Description : "" ,
16+ ReadContext : func (ctx context.Context , rd * schema.ResourceData , i interface {}) diag.Diagnostics {
17+ rd .SetId (uuid .NewString ())
18+
19+ return nil
20+ },
21+ Schema : map [string ]* schema.Schema {
22+ "name" : {
23+ Type : schema .TypeString ,
24+ Description : "Name of the workspace preset." ,
25+ Required : true ,
26+ },
27+ "parameters" : {
28+ Type : schema .TypeMap ,
29+ Description : "Parameters of the workspace preset." ,
30+ Required : true ,
31+ },
32+ },
33+ }
34+ }
Original file line number Diff line number Diff line change 1+ package provider_test
2+
3+ import (
4+ "testing"
5+
6+ "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+ "github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
8+ "github.com/stretchr/testify/require"
9+ )
10+
11+ func TestWorkspacePreset (t * testing.T ) {
12+ resource .Test (t , resource.TestCase {
13+ ProviderFactories : coderFactory (),
14+ IsUnitTest : true ,
15+ Steps : []resource.TestStep {{
16+ Config : `
17+ data "coder_workspace_preset" "preset_1" {
18+ name = "preset_1"
19+ parameters = {
20+ "region" = "us-east1-a"
21+ }
22+ }` ,
23+ Check : func (state * terraform.State ) error {
24+ require .Len (t , state .Modules , 1 )
25+ require .Len (t , state .Modules [0 ].Resources , 1 )
26+ resource := state .Modules [0 ].Resources ["data.coder_workspace_preset.preset_1" ]
27+ require .NotNil (t , resource )
28+ attrs := resource .Primary .Attributes
29+ require .Equal (t , attrs ["name" ], "preset_1" )
30+ require .Equal (t , attrs ["parameters.region" ], "us-east1-a" )
31+ return nil
32+ },
33+ }},
34+ })
35+ }
You can’t perform that action at this time.
0 commit comments