-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
153 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
provider "coder" {} | ||
|
||
data "coder_parameter" "os_selector" { | ||
name = "os_selector" | ||
display_name = "Operating System" | ||
mutable = false | ||
|
||
default = "osx" | ||
|
||
option { | ||
icon = "/icons/linux.png" | ||
name = "Linux" | ||
value = "linux" | ||
} | ||
option { | ||
icon = "/icons/osx.png" | ||
name = "OSX" | ||
value = "osx" | ||
} | ||
option { | ||
icon = "/icons/windows.png" | ||
name = "Windows" | ||
value = "windows" | ||
} | ||
} | ||
|
||
data "coder_parameter" "feature_cache_enabled" { | ||
name = "feature_cache_enabled" | ||
display_name = "Enable cache?" | ||
type = "bool" | ||
|
||
default = false | ||
} | ||
|
||
data "coder_parameter" "feature_debug_enabled" { | ||
name = "feature_debug_enabled" | ||
display_name = "Enable debug?" | ||
type = "bool" | ||
|
||
default = true | ||
} | ||
|
||
data "coder_workspace_tags" "custom_workspace_tags" { | ||
tags = { | ||
"cluster" = "developers" | ||
"os" = data.coder_parameter.os_selector.value | ||
"debug" = "${data.coder_parameter.feature_debug_enabled.value}+12345" | ||
"cache" = data.coder_parameter.feature_cache_enabled.value == "true" ? "nix-with-cache" : "no-cache" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package provider | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/google/uuid" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
type WorkspaceTags struct { | ||
Tags map[string]string | ||
} | ||
|
||
func workspaceTagDataSource() *schema.Resource { | ||
return &schema.Resource{ | ||
Description: "Use this data source to configure workspace tags to select provisioners.", | ||
ReadContext: func(ctx context.Context, rd *schema.ResourceData, i interface{}) diag.Diagnostics { | ||
rd.SetId(uuid.NewString()) | ||
return nil | ||
}, | ||
Schema: map[string]*schema.Schema{ | ||
"tags": { | ||
Type: schema.TypeMap, | ||
Description: `Key-value map with workspace tags`, | ||
ForceNew: true, | ||
Optional: true, | ||
Elem: &schema.Schema{Type: schema.TypeString}, | ||
}, | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package provider_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/coder/terraform-provider-coder/provider" | ||
) | ||
|
||
func TestWorkspaceTags(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
Providers: map[string]*schema.Provider{ | ||
"coder": provider.New(), | ||
}, | ||
IsUnitTest: true, | ||
Steps: []resource.TestStep{{ | ||
Config: ` | ||
provider "coder" { | ||
} | ||
data "coder_parameter" "animal" { | ||
name = "animal" | ||
type = "string" | ||
default = "chris" | ||
} | ||
data "coder_workspace_tags" "wt" { | ||
tags = { | ||
"cat" = "james" | ||
"dog" = data.coder_parameter.animal.value | ||
} | ||
}`, | ||
Check: func(state *terraform.State) error { | ||
require.Len(t, state.Modules, 1) | ||
require.Len(t, state.Modules[0].Resources, 2) | ||
resource := state.Modules[0].Resources["data.coder_workspace_tags.wt"] | ||
require.NotNil(t, resource) | ||
|
||
attribs := resource.Primary.Attributes | ||
require.Equal(t, "james", attribs["tags.cat"]) | ||
require.Equal(t, "chris", attribs["tags.dog"]) | ||
return nil | ||
}, | ||
}}, | ||
}) | ||
} |