Skip to content

Commit 56df8df

Browse files
committed
Merge branch 'fix-panic-data-templates' into 6368-legacy-variable-name
2 parents a666539 + 5eaf298 commit 56df8df

22 files changed

+365
-295
lines changed

coderd/apidoc/docs.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/dbfake/databasefake.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2826,6 +2826,7 @@ func (q *fakeQuerier) InsertTemplateVersionParameter(_ context.Context, arg data
28262826
ValidationMax: arg.ValidationMax,
28272827
ValidationMonotonic: arg.ValidationMonotonic,
28282828
Required: arg.Required,
2829+
LegacyVariableName: arg.LegacyVariableName,
28292830
}
28302831
q.templateVersionParameters = append(q.templateVersionParameters, param)
28312832
return param, nil

coderd/database/dump.sql

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE template_version_parameters DROP COLUMN legacy_variable_name;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ALTER TABLE template_version_parameters ADD COLUMN legacy_variable_name text NOT NULL DEFAULT '';
2+
3+
COMMENT ON COLUMN template_version_parameters.legacy_variable_name IS 'Name of the legacy variable for migration purposes';

coderd/database/models.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries.sql.go

Lines changed: 10 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/templateversionparameters.sql

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ INSERT INTO
1414
validation_max,
1515
validation_error,
1616
validation_monotonic,
17-
required
17+
required,
18+
legacy_variable_name
1819
)
1920
VALUES
2021
(
@@ -31,7 +32,8 @@ VALUES
3132
$11,
3233
$12,
3334
$13,
34-
$14
35+
$14,
36+
$15
3537
) RETURNING *;
3638

3739
-- name: GetTemplateVersionParameters :many

coderd/provisionerdserver/provisionerdserver.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,7 @@ func (server *Server) CompleteJob(ctx context.Context, completed *proto.Complete
835835
ValidationMax: richParameter.ValidationMax,
836836
ValidationMonotonic: richParameter.ValidationMonotonic,
837837
Required: richParameter.Required,
838+
LegacyVariableName: richParameter.LegacyVariableName,
838839
})
839840
if err != nil {
840841
return nil, xerrors.Errorf("insert parameter: %w", err)

coderd/templateversions.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1622,6 +1622,7 @@ func convertTemplateVersionParameter(param database.TemplateVersionParameter) (c
16221622
ValidationError: param.ValidationError,
16231623
ValidationMonotonic: codersdk.ValidationMonotonicOrder(param.ValidationMonotonic),
16241624
Required: param.Required,
1625+
LegacyVariableName: param.LegacyVariableName,
16251626
}, nil
16261627
}
16271628

coderd/workspacebuilds.go

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,39 @@ func (api *API) postWorkspaceBuilds(rw http.ResponseWriter, r *http.Request) {
477477
}
478478
apiLastBuildParameters := convertWorkspaceBuildParameters(lastBuildParameters)
479479

480+
legacyParameters, err := api.Database.ParameterValues(ctx, database.ParameterValuesParams{
481+
Scopes: []database.ParameterScope{database.ParameterScopeWorkspace},
482+
ScopeIds: []uuid.UUID{workspace.ID},
483+
})
484+
if err != nil && !xerrors.Is(err, sql.ErrNoRows) {
485+
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
486+
Message: "Error fetching previous legacy parameters.",
487+
Detail: err.Error(),
488+
})
489+
return
490+
}
491+
492+
// Rich parameters migration: include legacy variables to the last build parameters
493+
for _, templateVersionParameter := range templateVersionParameters {
494+
// Check if parameter is defined in previous build
495+
if _, found := findWorkspaceBuildParameter(apiLastBuildParameters, templateVersionParameter.Name); found {
496+
continue
497+
}
498+
499+
// Check if legacy variable is defined
500+
for _, legacyParameter := range legacyParameters {
501+
if legacyParameter.Name != templateVersionParameter.Name {
502+
continue
503+
}
504+
505+
apiLastBuildParameters = append(apiLastBuildParameters, codersdk.WorkspaceBuildParameter{
506+
Name: templateVersionParameter.Name,
507+
Value: legacyParameter.SourceValue,
508+
})
509+
break
510+
}
511+
}
512+
480513
err = codersdk.ValidateWorkspaceBuildParameters(templateVersionParameters, createBuild.RichParameterValues, apiLastBuildParameters)
481514
if err != nil {
482515
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
@@ -506,26 +539,6 @@ func (api *API) postWorkspaceBuilds(rw http.ResponseWriter, r *http.Request) {
506539
}
507540
}
508541

509-
legacyParameters, err := api.Database.ParameterValues(ctx, database.ParameterValuesParams{
510-
Scopes: []database.ParameterScope{database.ParameterScopeWorkspace},
511-
ScopeIds: []uuid.UUID{workspace.ID},
512-
})
513-
if err != nil && !xerrors.Is(err, sql.ErrNoRows) {
514-
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
515-
Message: "Error fetching previous legacy parameters.",
516-
Detail: err.Error(),
517-
})
518-
return
519-
}
520-
521-
if createBuild.Transition == codersdk.WorkspaceTransitionStart &&
522-
len(legacyParameters) > 0 && len(parameters) > 0 {
523-
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
524-
Message: "Rich parameters can't be used together with legacy parameters.",
525-
})
526-
return
527-
}
528-
529542
var workspaceBuild database.WorkspaceBuild
530543
var provisionerJob database.ProvisionerJob
531544
// This must happen in a transaction to ensure history can be inserted, and

codersdk/templateversions.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ type TemplateVersionParameter struct {
5454
ValidationMax int32 `json:"validation_max,omitempty"`
5555
ValidationMonotonic ValidationMonotonicOrder `json:"validation_monotonic,omitempty" enums:"increasing,decreasing"`
5656
Required bool `json:"required"`
57+
LegacyVariableName string `json:"legacy_variable_name,omitempty"`
5758
}
5859

5960
// TemplateVersionParameterOption represents a selectable option for a template parameter.

docs/api/schemas.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3734,6 +3734,7 @@ Parameter represents a set value for the scope.
37343734
"description": "string",
37353735
"description_plaintext": "string",
37363736
"icon": "string",
3737+
"legacy_variable_name": "string",
37373738
"mutable": true,
37383739
"name": "string",
37393740
"options": [
@@ -3762,6 +3763,7 @@ Parameter represents a set value for the scope.
37623763
| `description` | string | false | | |
37633764
| `description_plaintext` | string | false | | |
37643765
| `icon` | string | false | | |
3766+
| `legacy_variable_name` | string | false | | |
37653767
| `mutable` | boolean | false | | |
37663768
| `name` | string | false | | |
37673769
| `options` | array of [codersdk.TemplateVersionParameterOption](#codersdktemplateversionparameteroption) | false | | |

docs/api/templates.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2209,6 +2209,7 @@ curl -X GET http://coder-server:8080/api/v2/templateversions/{templateversion}/r
22092209
"description": "string",
22102210
"description_plaintext": "string",
22112211
"icon": "string",
2212+
"legacy_variable_name": "string",
22122213
"mutable": true,
22132214
"name": "string",
22142215
"options": [
@@ -2247,6 +2248,7 @@ Status Code **200**
22472248
| `» description` | string | false | | |
22482249
| `» description_plaintext` | string | false | | |
22492250
| `» icon` | string | false | | |
2251+
| `» legacy_variable_name` | string | false | | |
22502252
| `» mutable` | boolean | false | | |
22512253
| `» name` | string | false | | |
22522254
| `» options` | array | false | | |

go.mod

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ require (
7575
github.com/codeclysm/extract v2.2.0+incompatible
7676
github.com/coder/flog v1.0.0
7777
github.com/coder/retry v1.3.1-0.20230210155434-e90a2e1e091d
78-
github.com/coder/terraform-provider-coder v0.6.15
78+
github.com/coder/terraform-provider-coder v0.6.17
7979
github.com/coreos/go-oidc/v3 v3.4.0
8080
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf
8181
github.com/creack/pty v1.1.18
@@ -183,13 +183,17 @@ require (
183183
github.com/dustin/go-humanize v1.0.1 // indirect
184184
github.com/google/flatbuffers v23.1.21+incompatible // indirect
185185
github.com/h2non/filetype v1.1.3 // indirect
186+
github.com/hashicorp/go-plugin v1.4.4 // indirect
187+
github.com/hashicorp/terraform-registry-address v0.0.0-20220623143253-7d51757b572c // indirect
188+
github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734 // indirect
186189
github.com/json-iterator/go v1.1.12 // indirect
187190
github.com/juju/errors v1.0.0 // indirect
188191
github.com/mattn/go-localereader v0.0.1 // indirect
189192
github.com/mattn/go-sqlite3 v1.14.15 // indirect
190193
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
191194
github.com/modern-go/reflect2 v1.0.2 // indirect
192195
github.com/muesli/cancelreader v0.2.2 // indirect
196+
github.com/oklog/run v1.0.0 // indirect
193197
)
194198

195199
require (

go.sum

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,8 @@ github.com/coder/tailscale v1.1.1-0.20230307022319-1e5e724a3949 h1:8WfMfRTDaEpnm
380380
github.com/coder/tailscale v1.1.1-0.20230307022319-1e5e724a3949/go.mod h1:jpg+77g19FpXL43U1VoIqoSg1K/Vh5CVxycGldQ8KhA=
381381
github.com/coder/terraform-provider-coder v0.6.15 h1:Llvh4RwxSQ/goy7ToTOeHf3tdEz+79qbyOh61hNnJs0=
382382
github.com/coder/terraform-provider-coder v0.6.15/go.mod h1:UIfU3bYNeSzJJvHyJ30tEKjD6Z9utloI+HUM/7n94CY=
383+
github.com/coder/terraform-provider-coder v0.6.17 h1:YvjM5nQx5RO+gXsYIv++CkiWCuJueQdJaPrsjnkZ4XQ=
384+
github.com/coder/terraform-provider-coder v0.6.17/go.mod h1:UIfU3bYNeSzJJvHyJ30tEKjD6Z9utloI+HUM/7n94CY=
383385
github.com/containerd/aufs v0.0.0-20200908144142-dab0cbea06f4/go.mod h1:nukgQABAEopAHvB6j7cnP5zJ+/3aVcE7hCYqvIwAHyE=
384386
github.com/containerd/aufs v0.0.0-20201003224125-76a6863f2989/go.mod h1:AkGGQs9NM2vtYHaUen+NljV0/baGCAPELGm2q9ZXpWU=
385387
github.com/containerd/aufs v0.0.0-20210316121734-20793ff83c97/go.mod h1:kL5kd6KM5TzQjR79jljyi4olc1Vrx6XBlcyj3gNv2PU=
@@ -1025,6 +1027,7 @@ github.com/hashicorp/go-multierror v1.1.0/go.mod h1:spPvp8C1qA32ftKqdAHm4hHTbPw+
10251027
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
10261028
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
10271029
github.com/hashicorp/go-plugin v1.4.4 h1:NVdrSdFRt3SkZtNckJ6tog7gbpRrcbOjQi/rgF7JYWQ=
1030+
github.com/hashicorp/go-plugin v1.4.4/go.mod h1:viDMjcLJuDui6pXb8U4HVfb8AamCWhHGUjr2IrTF67s=
10281031
github.com/hashicorp/go-reap v0.0.0-20170704170343-bf58d8a43e7b h1:3GrpnZQBxcMj1gCXQLelfjCT1D5MPGTuGMKHVzSIH6A=
10291032
github.com/hashicorp/go-reap v0.0.0-20170704170343-bf58d8a43e7b/go.mod h1:qIFzeFcJU3OIFk/7JreWXcUjFmcCaeHTH9KoNyHYVCs=
10301033
github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU=
@@ -1035,6 +1038,7 @@ github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/b
10351038
github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
10361039
github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8=
10371040
github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
1041+
github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
10381042
github.com/hashicorp/go-version v1.2.1/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
10391043
github.com/hashicorp/go-version v1.5.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
10401044
github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek=
@@ -1071,7 +1075,9 @@ github.com/hashicorp/terraform-plugin-log v0.7.0/go.mod h1:p4R1jWBXRTvL4odmEkFfD
10711075
github.com/hashicorp/terraform-plugin-sdk/v2 v2.20.0 h1:+KxZULPsbjpAVoP0WNj/8aVW6EqpcX5JcUcQ5wl7Da4=
10721076
github.com/hashicorp/terraform-plugin-sdk/v2 v2.20.0/go.mod h1:DwGJG3KNxIPluVk6hexvDfYR/MS/eKGpiztJoT3Bbbw=
10731077
github.com/hashicorp/terraform-registry-address v0.0.0-20220623143253-7d51757b572c h1:D8aRO6+mTqHfLsK/BC3j5OAoogv1WLRWzY1AaTo3rBg=
1078+
github.com/hashicorp/terraform-registry-address v0.0.0-20220623143253-7d51757b572c/go.mod h1:Wn3Na71knbXc1G8Lh+yu/dQWWJeFQEpDeJMtWMtlmNI=
10741079
github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734 h1:HKLsbzeOsfXmKNpr3GiT18XAblV0BjCbzL8KQAMZGa0=
1080+
github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734/go.mod h1:kNDNcF7sN4DocDLBkQYz73HGKwN1ANB1blq4lIYLYvg=
10751081
github.com/hashicorp/yamux v0.0.0-20220718163420-dd80a7ee44ce h1:7FO+LmZwiG/eDsBWo50ZeqV5PoH0gwiM1mxFajXAkas=
10761082
github.com/hashicorp/yamux v0.0.0-20220718163420-dd80a7ee44ce/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ=
10771083
github.com/hdevalence/ed25519consensus v0.0.0-20220222234857-c00d1f31bab3 h1:aSVUgRRRtOrZOC1fYmY9gV0e9z/Iu+xNVSASWjsuyGU=
@@ -1495,6 +1501,7 @@ github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d/go.mod h1:YUTz3bUH
14951501
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
14961502
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
14971503
github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw=
1504+
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
14981505
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
14991506
github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo=
15001507
github.com/olekukonko/tablewriter v0.0.1/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo=
@@ -2163,6 +2170,7 @@ golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLL
21632170
golang.org/x/net v0.0.0-20191002035440-2ec189313ef0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
21642171
golang.org/x/net v0.0.0-20191004110552-13f9640d40b9/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
21652172
golang.org/x/net v0.0.0-20191007182048-72f939374954/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
2173+
golang.org/x/net v0.0.0-20191009170851-d66e71096ffb/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
21662174
golang.org/x/net v0.0.0-20191112182307-2180aed22343/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
21672175
golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
21682176
golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=

provisioner/terraform/resources.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -445,13 +445,14 @@ func ConvertState(modules []*tfjson.StateModule, rawGraph string) (*State, error
445445
return nil, xerrors.Errorf("decode map values for coder_parameter.%s: %w", resource.Name, err)
446446
}
447447
protoParam := &proto.RichParameter{
448-
Name: param.Name,
449-
Description: param.Description,
450-
Type: param.Type,
451-
Mutable: param.Mutable,
452-
DefaultValue: param.Default,
453-
Icon: param.Icon,
454-
Required: !param.Optional,
448+
Name: param.Name,
449+
Description: param.Description,
450+
Type: param.Type,
451+
Mutable: param.Mutable,
452+
DefaultValue: param.Default,
453+
Icon: param.Icon,
454+
Required: !param.Optional,
455+
LegacyVariableName: param.LegacyVariableName,
455456
}
456457
if len(param.Validation) == 1 {
457458
protoParam.ValidationRegex = param.Validation[0].Regex

0 commit comments

Comments
 (0)