Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: support ephemeral parameters#138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
mtojek merged 3 commits intocoder:mainfrommtojek:6828-ephemeral
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletionsdocs/data-sources/parameter.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -24,6 +24,7 @@ Use this data source to configure editable options for workspaces.
- `default` (String) A default value for the parameter.
- `description` (String) Describe what this parameter does.
- `display_name` (String) The displayed name of the parameter as it will appear in the interface.
- `ephemeral` (Boolean) The value of an ephemeral parameter will not be preserved between consecutive workspace builds.
- `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>"`.
- `legacy_variable` (String, Deprecated) Reference to the Terraform variable. Coder will use it to lookup the default value.
- `legacy_variable_name` (String, Deprecated) Name of the legacy Terraform variable. Coder will use it to lookup the variable value.
Expand Down
6 changes: 4 additions & 2 deletionsexamples/resources/coder_parameter/resource.tf
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -74,8 +74,10 @@ data "coder_parameter" "cat_lives" {
}

data "coder_parameter" "fairy_tale" {
name = "Fairy Tale"
type = "string"
name = "Fairy Tale"
type = "string"
mutable = true
ephemeral = true
}

data "coder_parameter" "users" {
Expand Down
16 changes: 14 additions & 2 deletionsprovider/parameter.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -56,8 +56,8 @@ type Parameter struct {
Option []Option
Validation []Validation
Optional bool

Order int
Order int
Ephemeral bool

LegacyVariableName string `mapstructure:"legacy_variable_name"`
LegacyVariable string `mapstructure:"legacy_variable"`
Expand DownExpand Up@@ -93,6 +93,7 @@ func parameterDataSource() *schema.Resource {
Validation interface{}
Optional interface{}
Order interface{}
Ephemeral interface{}

LegacyVariableName interface{}
LegacyVariable interface{}
Expand DownExpand Up@@ -126,6 +127,7 @@ func parameterDataSource() *schema.Resource {
return val
}(),
Order: rd.Get("order"),
Ephemeral: rd.Get("ephemeral"),
LegacyVariableName: rd.Get("legacy_variable_name"),
LegacyVariable: rd.Get("legacy_variable"),
}, &parameter)
Expand All@@ -146,6 +148,10 @@ func parameterDataSource() *schema.Resource {
}
rd.Set("value", value)

if !parameter.Mutable && parameter.Ephemeral {
return diag.Errorf("parameter can't be immutable and ephemeral")
}

if len(parameter.Validation) == 1 {
validation := &parameter.Validation[0]
err = validation.Valid(parameter.Type, value)
Expand DownExpand Up@@ -340,6 +346,12 @@ func parameterDataSource() *schema.Resource {
Optional: true,
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).",
},
"ephemeral": {
Type: schema.TypeBool,
Default: false,
Optional: true,
Description: "The value of an ephemeral parameter will not be preserved between consecutive workspace builds.",
},
"legacy_variable_name": {
Type: schema.TypeString,
Optional: true,
Expand Down
13 changes: 13 additions & 0 deletionsprovider/parameter_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -44,6 +44,7 @@ func TestParameter(t *testing.T) {
description = "Select for east!"
}
order = 5
ephemeral = true
}
`,
Check: func(state *terraform.ResourceState) {
Expand All@@ -64,6 +65,7 @@ func TestParameter(t *testing.T) {
"option.1.icon": "/icon/east.svg",
"option.1.description": "Select for east!",
"order": "5",
"ephemeral": "true",
} {
require.Equal(t, value, attrs[key])
}
Expand DownExpand Up@@ -602,6 +604,17 @@ data "coder_parameter" "region" {
}
`,
ExpectError: regexp.MustCompile("a min cannot be specified for a bool type"),
}, {
Name: "ImmutableEphemeralError",
Config: `
data "coder_parameter" "region" {
name = "Region"
type = "string"
mutable = false
ephemeral = true
}
`,
ExpectError: regexp.MustCompile("parameter can't be immutable and ephemeral"),
}} {
tc := tc
t.Run(tc.Name, func(t *testing.T) {
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp