Content-Length: 12178 | pFad | http://github.com/coder/terraform-provider-coder/pull/422.diff
thub.com
diff --git a/docs/data-sources/workspace_preset.md b/docs/data-sources/workspace_preset.md
index 69057403..e7de98e4 100644
--- a/docs/data-sources/workspace_preset.md
+++ b/docs/data-sources/workspace_preset.md
@@ -21,7 +21,9 @@ provider "coder" {}
# See the coder_parameter data source's documentation for examples of how to define
# parameters like the ones used below.
data "coder_workspace_preset" "example" {
- name = "example"
+ name = "example"
+ description = "Example description of what this preset does."
+ icon = "/icon/example.svg"
parameters = {
(data.coder_parameter.example.name) = "us-central1-a"
(data.coder_parameter.ami.name) = "ami-xxxxxxxx"
@@ -30,8 +32,10 @@ data "coder_workspace_preset" "example" {
# Example of a default preset that will be pre-selected for users
data "coder_workspace_preset" "standard" {
- name = "Standard"
- default = true
+ name = "Standard"
+ description = "A workspace preset with medium compute in the US West region."
+ icon = "/icon/standard.svg"
+ default = true
parameters = {
(data.coder_parameter.instance_type.name) = "t3.medium"
(data.coder_parameter.region.name) = "us-west-2"
@@ -49,6 +53,8 @@ data "coder_workspace_preset" "standard" {
### Optional
- `default` (Boolean) Whether this preset should be selected by default when creating a workspace. Only one preset per template can be marked as default.
+- `description` (String) Describe what this preset does.
+- `icon` (String) A URL to an icon that will display in the dashboard. View built-in icons [here](https://github.com/coder/coder/tree/main/site/static/icon). Use a built-in icon with `"${data.coder_workspace.me.access_url}/icon/"`.
- `parameters` (Map of String) Workspace parameters that will be set by the workspace preset. For simple templates that only need prebuilds, you may define a preset with zero parameters. Because workspace parameters may change between Coder template versions, preset parameters are allowed to define values for parameters that do not exist in the current template version.
- `prebuilds` (Block Set, Max: 1) Configuration for prebuilt workspaces associated with this preset. Coder will maintain a pool of standby workspaces based on this configuration. When a user creates a workspace using this preset, they are assigned a prebuilt workspace instead of waiting for a new one to build. See prebuilt workspace documentation [here](https://coder.com/docs/admin/templates/extending-templates/prebuilt-workspaces.md) (see [below for nested schema](#nestedblock--prebuilds))
diff --git a/examples/data-sources/coder_workspace_preset/data-source.tf b/examples/data-sources/coder_workspace_preset/data-source.tf
index 3c245f7a..89150761 100644
--- a/examples/data-sources/coder_workspace_preset/data-source.tf
+++ b/examples/data-sources/coder_workspace_preset/data-source.tf
@@ -6,7 +6,9 @@ provider "coder" {}
# See the coder_parameter data source's documentation for examples of how to define
# parameters like the ones used below.
data "coder_workspace_preset" "example" {
- name = "example"
+ name = "example"
+ description = "Example description of what this preset does."
+ icon = "/icon/example.svg"
parameters = {
(data.coder_parameter.example.name) = "us-central1-a"
(data.coder_parameter.ami.name) = "ami-xxxxxxxx"
@@ -15,8 +17,10 @@ data "coder_workspace_preset" "example" {
# Example of a default preset that will be pre-selected for users
data "coder_workspace_preset" "standard" {
- name = "Standard"
- default = true
+ name = "Standard"
+ description = "A workspace preset with medium compute in the US West region."
+ icon = "/icon/standard.svg"
+ default = true
parameters = {
(data.coder_parameter.instance_type.name) = "t3.medium"
(data.coder_parameter.region.name) = "us-west-2"
diff --git a/integration/integration_test.go b/integration/integration_test.go
index ec0b5e4f..423447c9 100644
--- a/integration/integration_test.go
+++ b/integration/integration_test.go
@@ -93,6 +93,8 @@ func TestIntegration(t *testing.T) {
"workspace_parameter.value": `param value`,
"workspace_parameter.icon": `param icon`,
"workspace_preset.name": `preset`,
+ "workspace_preset.description": `preset description`,
+ "workspace_preset.icon": `preset icon`,
"workspace_preset.default": `true`,
"workspace_preset.parameters.param": `preset param value`,
"workspace_preset.prebuilds.instances": `1`,
diff --git a/integration/test-data-source/main.tf b/integration/test-data-source/main.tf
index 5d312b1a..cc4802d3 100644
--- a/integration/test-data-source/main.tf
+++ b/integration/test-data-source/main.tf
@@ -20,8 +20,10 @@ data "coder_parameter" "param" {
icon = "param icon"
}
data "coder_workspace_preset" "preset" {
- name = "preset"
- default = true
+ name = "preset"
+ description = "preset description"
+ icon = "preset icon"
+ default = true
parameters = {
(data.coder_parameter.param.name) = "preset param value"
}
@@ -65,6 +67,8 @@ locals {
"workspace_parameter.value" : data.coder_parameter.param.value,
"workspace_parameter.icon" : data.coder_parameter.param.icon,
"workspace_preset.name" : data.coder_workspace_preset.preset.name,
+ "workspace_preset.description" : data.coder_workspace_preset.preset.description,
+ "workspace_preset.icon" : data.coder_workspace_preset.preset.icon,
"workspace_preset.default" : tostring(data.coder_workspace_preset.preset.default),
"workspace_preset.parameters.param" : data.coder_workspace_preset.preset.parameters.param,
"workspace_preset.prebuilds.instances" : tostring(one(data.coder_workspace_preset.preset.prebuilds).instances),
diff --git a/provider/workspace_preset.go b/provider/workspace_preset.go
index 1d7576e9..393c7b7f 100644
--- a/provider/workspace_preset.go
+++ b/provider/workspace_preset.go
@@ -18,9 +18,11 @@ import (
var PrebuildsCRONParser = rbcron.NewParser(rbcron.Minute | rbcron.Hour | rbcron.Dom | rbcron.Month | rbcron.Dow)
type WorkspacePreset struct {
- Name string `mapstructure:"name"`
- Default bool `mapstructure:"default"`
- Parameters map[string]string `mapstructure:"parameters"`
+ Name string `mapstructure:"name"`
+ Description string `mapstructure:"description"`
+ Icon string `mapstructure:"icon"`
+ Default bool `mapstructure:"default"`
+ Parameters map[string]string `mapstructure:"parameters"`
// There should always be only one prebuild block, but Terraform's type system
// still parses them as a slice, so we need to handle it as such. We could use
// an anonymous type and rd.Get to avoid a slice here, but that would not be possible
@@ -93,6 +95,24 @@ func workspacePresetDataSource() *schema.Resource {
Required: true,
ValidateFunc: validation.StringIsNotEmpty,
},
+ "description": {
+ Type: schema.TypeString,
+ Optional: true,
+ Description: "Describe what this preset does.",
+ ValidateFunc: validation.StringLenBetween(0, 128),
+ },
+ "icon": {
+ Type: schema.TypeString,
+ Description: "A URL to an icon that will display in the dashboard. View built-in " +
+ "icons [here](https://github.com/coder/coder/tree/main/site/static/icon). Use a " +
+ "built-in icon with `\"${data.coder_workspace.me.access_url}/icon/\"`.",
+ ForceNew: true,
+ Optional: true,
+ ValidateFunc: validation.All(
+ helpers.ValidateURL,
+ validation.StringLenBetween(0, 256),
+ ),
+ },
"default": {
Type: schema.TypeBool,
Description: "Whether this preset should be selected by default when creating a workspace. Only one preset per template can be marked as default.",
diff --git a/provider/workspace_preset_test.go b/provider/workspace_preset_test.go
index 073193c6..d10b8126 100644
--- a/provider/workspace_preset_test.go
+++ b/provider/workspace_preset_test.go
@@ -23,6 +23,11 @@ func TestWorkspacePreset(t *testing.T) {
Config: `
data "coder_workspace_preset" "preset_1" {
name = "preset_1"
+ description = <<-EOT
+ # Select the machine image
+ See the [registry](https://container.registry.blah/namespace) for options.
+ EOT
+ icon = "/icon/region.svg"
parameters = {
"region" = "us-east1-a"
}
@@ -34,6 +39,8 @@ func TestWorkspacePreset(t *testing.T) {
require.NotNil(t, resource)
attrs := resource.Primary.Attributes
require.Equal(t, attrs["name"], "preset_1")
+ require.Equal(t, attrs["description"], "# Select the machine image\nSee the [registry](https://container.registry.blah/namespace) for options.\n")
+ require.Equal(t, attrs["icon"], "/icon/region.svg")
require.Equal(t, attrs["parameters.region"], "us-east1-a")
return nil
},
@@ -76,6 +83,76 @@ func TestWorkspacePreset(t *testing.T) {
// So we test it here to make sure we don't regress.
ExpectError: regexp.MustCompile("Incorrect attribute value type"),
},
+ {
+ Name: "Description field is empty",
+ Config: `
+ data "coder_workspace_preset" "preset_1" {
+ name = "preset_1"
+ description = ""
+ parameters = {
+ "region" = "us-east1-a"
+ }
+ }`,
+ // This validation is done by Terraform, but it could still break if we misconfigure the schema.
+ // So we test it here to make sure we don't regress.
+ ExpectError: nil,
+ },
+ {
+ Name: "Description field exceeds maximum supported length (128 characters)",
+ Config: `
+ data "coder_workspace_preset" "preset_1" {
+ name = "preset_1"
+ description = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur vehicula leo sit amet mi laoreet, sed ornare velit tincidunt. Proin gravida lacinia blandit."
+ parameters = {
+ "region" = "us-east1-a"
+ }
+ }`,
+ // This validation is done by Terraform, but it could still break if we misconfigure the schema.
+ // So we test it here to make sure we don't regress.
+ ExpectError: regexp.MustCompile(`expected length of description to be in the range \(0 - 128\)`),
+ },
+ {
+ Name: "Icon field is empty",
+ Config: `
+ data "coder_workspace_preset" "preset_1" {
+ name = "preset_1"
+ icon = ""
+ parameters = {
+ "region" = "us-east1-a"
+ }
+ }`,
+ // This validation is done by Terraform, but it could still break if we misconfigure the schema.
+ // So we test it here to make sure we don't regress.
+ ExpectError: nil,
+ },
+ {
+ Name: "Icon field is an invalid URL",
+ Config: `
+ data "coder_workspace_preset" "preset_1" {
+ name = "preset_1"
+ icon = "/icon%.svg"
+ parameters = {
+ "region" = "us-east1-a"
+ }
+ }`,
+ // This validation is done by Terraform, but it could still break if we misconfigure the schema.
+ // So we test it here to make sure we don't regress.
+ ExpectError: regexp.MustCompile("invalid URL escape"),
+ },
+ {
+ Name: "Icon field exceeds maximum supported length (256 characters)",
+ Config: `
+ data "coder_workspace_preset" "preset_1" {
+ name = "preset_1"
+ icon = "https://example.com/path/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.svg"
+ parameters = {
+ "region" = "us-east1-a"
+ }
+ }`,
+ // This validation is done by Terraform, but it could still break if we misconfigure the schema.
+ // So we test it here to make sure we don't regress.
+ ExpectError: regexp.MustCompile(`expected length of icon to be in the range \(0 - 256\)`),
+ },
{
Name: "Parameters field is not provided",
Config: `
--- a PPN by Garber Painting Akron. With Image Size Reduction included!Fetched URL: http://github.com/coder/terraform-provider-coder/pull/422.diff
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy