Skip to content

Commit abc4f98

Browse files
authored
feat: support ephemeral parameters (#138)
1 parent 9236b0e commit abc4f98

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

Diff for: docs/data-sources/parameter.md

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Use this data source to configure editable options for workspaces.
2424
- `default` (String) A default value for the parameter.
2525
- `description` (String) Describe what this parameter does.
2626
- `display_name` (String) The displayed name of the parameter as it will appear in the interface.
27+
- `ephemeral` (Boolean) The value of an ephemeral parameter will not be preserved between consecutive workspace builds.
2728
- `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/<path>"`.
2829
- `legacy_variable` (String, Deprecated) Reference to the Terraform variable. Coder will use it to lookup the default value.
2930
- `legacy_variable_name` (String, Deprecated) Name of the legacy Terraform variable. Coder will use it to lookup the variable value.

Diff for: examples/resources/coder_parameter/resource.tf

+4-2
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,10 @@ data "coder_parameter" "cat_lives" {
7474
}
7575

7676
data "coder_parameter" "fairy_tale" {
77-
name = "Fairy Tale"
78-
type = "string"
77+
name = "Fairy Tale"
78+
type = "string"
79+
mutable = true
80+
ephemeral = true
7981
}
8082

8183
data "coder_parameter" "users" {

Diff for: provider/parameter.go

+14-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ type Parameter struct {
5656
Option []Option
5757
Validation []Validation
5858
Optional bool
59-
60-
Order int
59+
Order int
60+
Ephemeral bool
6161

6262
LegacyVariableName string `mapstructure:"legacy_variable_name"`
6363
LegacyVariable string `mapstructure:"legacy_variable"`
@@ -93,6 +93,7 @@ func parameterDataSource() *schema.Resource {
9393
Validation interface{}
9494
Optional interface{}
9595
Order interface{}
96+
Ephemeral interface{}
9697

9798
LegacyVariableName interface{}
9899
LegacyVariable interface{}
@@ -126,6 +127,7 @@ func parameterDataSource() *schema.Resource {
126127
return val
127128
}(),
128129
Order: rd.Get("order"),
130+
Ephemeral: rd.Get("ephemeral"),
129131
LegacyVariableName: rd.Get("legacy_variable_name"),
130132
LegacyVariable: rd.Get("legacy_variable"),
131133
}, &parameter)
@@ -146,6 +148,10 @@ func parameterDataSource() *schema.Resource {
146148
}
147149
rd.Set("value", value)
148150

151+
if !parameter.Mutable && parameter.Ephemeral {
152+
return diag.Errorf("parameter can't be immutable and ephemeral")
153+
}
154+
149155
if len(parameter.Validation) == 1 {
150156
validation := &parameter.Validation[0]
151157
err = validation.Valid(parameter.Type, value)
@@ -340,6 +346,12 @@ func parameterDataSource() *schema.Resource {
340346
Optional: true,
341347
Description: "The order determines the position of a template parameter in the UI/CLI presentation. The lowest order is shown first and parameters with equal order are sorted by name (ascending order).",
342348
},
349+
"ephemeral": {
350+
Type: schema.TypeBool,
351+
Default: false,
352+
Optional: true,
353+
Description: "The value of an ephemeral parameter will not be preserved between consecutive workspace builds.",
354+
},
343355
"legacy_variable_name": {
344356
Type: schema.TypeString,
345357
Optional: true,

Diff for: provider/parameter_test.go

+13
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ func TestParameter(t *testing.T) {
4444
description = "Select for east!"
4545
}
4646
order = 5
47+
ephemeral = true
4748
}
4849
`,
4950
Check: func(state *terraform.ResourceState) {
@@ -64,6 +65,7 @@ func TestParameter(t *testing.T) {
6465
"option.1.icon": "/icon/east.svg",
6566
"option.1.description": "Select for east!",
6667
"order": "5",
68+
"ephemeral": "true",
6769
} {
6870
require.Equal(t, value, attrs[key])
6971
}
@@ -602,6 +604,17 @@ data "coder_parameter" "region" {
602604
}
603605
`,
604606
ExpectError: regexp.MustCompile("a min cannot be specified for a bool type"),
607+
}, {
608+
Name: "ImmutableEphemeralError",
609+
Config: `
610+
data "coder_parameter" "region" {
611+
name = "Region"
612+
type = "string"
613+
mutable = false
614+
ephemeral = true
615+
}
616+
`,
617+
ExpectError: regexp.MustCompile("parameter can't be immutable and ephemeral"),
605618
}} {
606619
tc := tc
607620
t.Run(tc.Name, func(t *testing.T) {

0 commit comments

Comments
 (0)