- Notifications
You must be signed in to change notification settings - Fork1k
feat: allow new immutable parameters for existing workspaces#18579
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
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
//go:generate mockgen -destination ./rendermock.go -package rendermock github.com/coder/coder/v2/coderd/dynamicparameters Renderer | ||
package rendermock |
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -169,9 +169,15 @@ func ResolveParameters( | ||
parameterNames[parameter.Name] = struct{}{} | ||
if !firstBuild && !parameter.Mutable { | ||
originalValue, ok := originalValues[parameter.Name] | ||
// Immutable parameters should not be changed after the first build. | ||
// If the value matches the original value, that is fine. | ||
// | ||
// If the original value is not set, that means this is a new parameter. New | ||
// immutable parameters are allowed. This is an opinionated choice to prevent | ||
// workspaces failing to update or delete. Ideally we would block this, as | ||
// immutable parameters should only be able to be set at creation time. | ||
if ok && parameter.Value.AsString() != originalValue.Value { | ||
Comment on lines +172 to +180 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. This is the change. The rest is testing | ||
var src *hcl.Range | ||
if parameter.Source != nil { | ||
src = ¶meter.Source.HCLBlock().TypeRange | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package dynamicparameters_test | ||
import ( | ||
"testing" | ||
"github.com/google/uuid" | ||
"github.com/stretchr/testify/require" | ||
"go.uber.org/mock/gomock" | ||
"github.com/coder/coder/v2/coderd/database" | ||
"github.com/coder/coder/v2/coderd/dynamicparameters" | ||
"github.com/coder/coder/v2/coderd/dynamicparameters/rendermock" | ||
"github.com/coder/coder/v2/codersdk" | ||
"github.com/coder/coder/v2/testutil" | ||
"github.com/coder/preview" | ||
previewtypes "github.com/coder/preview/types" | ||
"github.com/coder/terraform-provider-coder/v2/provider" | ||
) | ||
func TestResolveParameters(t *testing.T) { | ||
t.Parallel() | ||
t.Run("NewImmutable", func(t *testing.T) { | ||
t.Parallel() | ||
ctrl := gomock.NewController(t) | ||
render := rendermock.NewMockRenderer(ctrl) | ||
// A single immutable parameter with no previous value. | ||
render.EXPECT(). | ||
Render(gomock.Any(), gomock.Any(), gomock.Any()). | ||
AnyTimes(). | ||
Return(&preview.Output{ | ||
Parameters: []previewtypes.Parameter{ | ||
{ | ||
ParameterData: previewtypes.ParameterData{ | ||
Name: "immutable", | ||
Type: previewtypes.ParameterTypeString, | ||
FormType: provider.ParameterFormTypeInput, | ||
Mutable: false, | ||
DefaultValue: previewtypes.StringLiteral("foo"), | ||
Required: true, | ||
}, | ||
Value: previewtypes.StringLiteral("foo"), | ||
Diagnostics: nil, | ||
}, | ||
}, | ||
}, nil) | ||
ctx := testutil.Context(t, testutil.WaitShort) | ||
values, err := dynamicparameters.ResolveParameters(ctx, uuid.New(), render, false, | ||
[]database.WorkspaceBuildParameter{}, // No previous values | ||
[]codersdk.WorkspaceBuildParameter{}, // No new build values | ||
[]database.TemplateVersionPresetParameter{}, // No preset values | ||
) | ||
require.NoError(t, err) | ||
require.Equal(t, map[string]string{"immutable": "foo"}, values) | ||
}) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
terraform { | ||
required_providers { | ||
coder = { | ||
source = "coder/coder" | ||
} | ||
} | ||
} | ||
data "coder_workspace_owner" "me" {} | ||
data "coder_parameter" "immutable" { | ||
name = "immutable" | ||
type = "string" | ||
mutable = false | ||
default = "Hello World" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
terraform { | ||
required_providers { | ||
coder = { | ||
source = "coder/coder" | ||
} | ||
} | ||
} | ||
data "coder_workspace_owner" "me" {} | ||
Uh oh!
There was an error while loading.Please reload this page.