chore: upgrade terraform-provider-coder & preview libs (#17738)

The changes in `coder/preview` necessitated the changes in
`codersdk/richparameters.go` & `provisioner/terraform/resources.go`.

---------

Signed-off-by: Danny Kopping <dannykopping@gmail.com>
Co-authored-by: Steven Masley <stevenmasley@gmail.com>
This commit is contained in:
Danny Kopping
2025-05-09 17:41:19 +02:00
committed by GitHub
parent 9d7630bf4b
commit 3ee95f14ce
7 changed files with 28 additions and 43 deletions

View File

@ -757,7 +757,7 @@ func TestUpdateValidateRichParameters(t *testing.T) {
err := inv.Run() err := inv.Run()
// TODO: improve validation so we catch this problem before it reaches the server // TODO: improve validation so we catch this problem before it reaches the server
// but for now just validate that the server actually catches invalid monotonicity // but for now just validate that the server actually catches invalid monotonicity
assert.ErrorContains(t, err, fmt.Sprintf("parameter value must be equal or greater than previous value: %s", tempVal)) assert.ErrorContains(t, err, "parameter value '1' must be equal or greater than previous value: 2")
}() }()
matches := []string{ matches := []string{

View File

@ -12,7 +12,7 @@ data "coder_parameter" "group" {
name = "group" name = "group"
default = try(data.coder_workspace_owner.me.groups[0], "") default = try(data.coder_workspace_owner.me.groups[0], "")
dynamic "option" { dynamic "option" {
for_each = data.coder_workspace_owner.me.groups for_each = concat(data.coder_workspace_owner.me.groups, "bloob")
content { content {
name = option.value name = option.value
value = option.value value = option.value

View File

@ -1,9 +1,8 @@
package codersdk package codersdk
import ( import (
"strconv"
"golang.org/x/xerrors" "golang.org/x/xerrors"
"tailscale.com/types/ptr"
"github.com/coder/terraform-provider-coder/v2/provider" "github.com/coder/terraform-provider-coder/v2/provider"
) )
@ -46,47 +45,31 @@ func ValidateWorkspaceBuildParameter(richParameter TemplateVersionParameter, bui
} }
func validateBuildParameter(richParameter TemplateVersionParameter, buildParameter *WorkspaceBuildParameter, lastBuildParameter *WorkspaceBuildParameter) error { func validateBuildParameter(richParameter TemplateVersionParameter, buildParameter *WorkspaceBuildParameter, lastBuildParameter *WorkspaceBuildParameter) error {
var value string var (
current string
previous *string
)
if buildParameter != nil { if buildParameter != nil {
value = buildParameter.Value current = buildParameter.Value
} }
if richParameter.Required && value == "" { if lastBuildParameter != nil {
previous = ptr.To(lastBuildParameter.Value)
}
if richParameter.Required && current == "" {
return xerrors.Errorf("parameter value is required") return xerrors.Errorf("parameter value is required")
} }
if value == "" { // parameter is optional, so take the default value if current == "" { // parameter is optional, so take the default value
value = richParameter.DefaultValue current = richParameter.DefaultValue
}
if lastBuildParameter != nil && lastBuildParameter.Value != "" && richParameter.Type == "number" && len(richParameter.ValidationMonotonic) > 0 {
prev, err := strconv.Atoi(lastBuildParameter.Value)
if err != nil {
return xerrors.Errorf("previous parameter value is not a number: %s", lastBuildParameter.Value)
}
current, err := strconv.Atoi(buildParameter.Value)
if err != nil {
return xerrors.Errorf("current parameter value is not a number: %s", buildParameter.Value)
}
switch richParameter.ValidationMonotonic {
case MonotonicOrderIncreasing:
if prev > current {
return xerrors.Errorf("parameter value must be equal or greater than previous value: %d", prev)
}
case MonotonicOrderDecreasing:
if prev < current {
return xerrors.Errorf("parameter value must be equal or lower than previous value: %d", prev)
}
}
} }
if len(richParameter.Options) > 0 { if len(richParameter.Options) > 0 {
var matched bool var matched bool
for _, opt := range richParameter.Options { for _, opt := range richParameter.Options {
if opt.Value == value { if opt.Value == current {
matched = true matched = true
break break
} }
@ -95,7 +78,6 @@ func validateBuildParameter(richParameter TemplateVersionParameter, buildParamet
if !matched { if !matched {
return xerrors.Errorf("parameter value must match one of options: %s", parameterValuesAsArray(richParameter.Options)) return xerrors.Errorf("parameter value must match one of options: %s", parameterValuesAsArray(richParameter.Options))
} }
return nil
} }
if !validationEnabled(richParameter) { if !validationEnabled(richParameter) {
@ -119,7 +101,7 @@ func validateBuildParameter(richParameter TemplateVersionParameter, buildParamet
Error: richParameter.ValidationError, Error: richParameter.ValidationError,
Monotonic: string(richParameter.ValidationMonotonic), Monotonic: string(richParameter.ValidationMonotonic),
} }
return validation.Valid(richParameter.Type, value) return validation.Valid(richParameter.Type, current, previous)
} }
func findBuildParameter(params []WorkspaceBuildParameter, parameterName string) (*WorkspaceBuildParameter, bool) { func findBuildParameter(params []WorkspaceBuildParameter, parameterName string) (*WorkspaceBuildParameter, bool) {

4
go.mod
View File

@ -101,7 +101,7 @@ require (
github.com/coder/quartz v0.1.3 github.com/coder/quartz v0.1.3
github.com/coder/retry v1.5.1 github.com/coder/retry v1.5.1
github.com/coder/serpent v0.10.0 github.com/coder/serpent v0.10.0
github.com/coder/terraform-provider-coder/v2 v2.4.0-pre1.0.20250417100258-c86bb5c3ddcd github.com/coder/terraform-provider-coder/v2 v2.4.0
github.com/coder/websocket v1.8.13 github.com/coder/websocket v1.8.13
github.com/coder/wgtunnel v0.1.13-0.20240522110300-ade90dfb2da0 github.com/coder/wgtunnel v0.1.13-0.20240522110300-ade90dfb2da0
github.com/coreos/go-oidc/v3 v3.14.1 github.com/coreos/go-oidc/v3 v3.14.1
@ -488,7 +488,7 @@ require (
require ( require (
github.com/anthropics/anthropic-sdk-go v0.2.0-beta.3 github.com/anthropics/anthropic-sdk-go v0.2.0-beta.3
github.com/coder/preview v0.0.2-0.20250506154333-6f500ca7b245 github.com/coder/preview v0.0.2-0.20250509141204-fc9484dbe506
github.com/fsnotify/fsnotify v1.9.0 github.com/fsnotify/fsnotify v1.9.0
github.com/kylecarbs/aisdk-go v0.0.8 github.com/kylecarbs/aisdk-go v0.0.8
github.com/mark3labs/mcp-go v0.25.0 github.com/mark3labs/mcp-go v0.25.0

8
go.sum
View File

@ -907,8 +907,8 @@ github.com/coder/pq v1.10.5-0.20240813183442-0c420cb5a048 h1:3jzYUlGH7ZELIH4XggX
github.com/coder/pq v1.10.5-0.20240813183442-0c420cb5a048/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/coder/pq v1.10.5-0.20240813183442-0c420cb5a048/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/coder/pretty v0.0.0-20230908205945-e89ba86370e0 h1:3A0ES21Ke+FxEM8CXx9n47SZOKOpgSE1bbJzlE4qPVs= github.com/coder/pretty v0.0.0-20230908205945-e89ba86370e0 h1:3A0ES21Ke+FxEM8CXx9n47SZOKOpgSE1bbJzlE4qPVs=
github.com/coder/pretty v0.0.0-20230908205945-e89ba86370e0/go.mod h1:5UuS2Ts+nTToAMeOjNlnHFkPahrtDkmpydBen/3wgZc= github.com/coder/pretty v0.0.0-20230908205945-e89ba86370e0/go.mod h1:5UuS2Ts+nTToAMeOjNlnHFkPahrtDkmpydBen/3wgZc=
github.com/coder/preview v0.0.2-0.20250506154333-6f500ca7b245 h1:RGoANNubwwPZF8puiYAk2qbzhVgipBMNu8WIrY1VIbI= github.com/coder/preview v0.0.2-0.20250509141204-fc9484dbe506 h1:rQ7Queq1IZwEBjEIk9EJsVx7XHQ+Rvo2h72/A88BnPg=
github.com/coder/preview v0.0.2-0.20250506154333-6f500ca7b245/go.mod h1:5VnO9yw7vq19hBgBqqBksE2BH53UTmNYH1QltkYLXJI= github.com/coder/preview v0.0.2-0.20250509141204-fc9484dbe506/go.mod h1:wXVvHiSmZv/7Q+Ug5I0B45TGM2U+YAjY4K3aB/6+KKo=
github.com/coder/quartz v0.1.3 h1:hA2nI8uUA2fNN9uhXv2I4xZD4aHkA7oH3g2t03v4xf8= github.com/coder/quartz v0.1.3 h1:hA2nI8uUA2fNN9uhXv2I4xZD4aHkA7oH3g2t03v4xf8=
github.com/coder/quartz v0.1.3/go.mod h1:vsiCc+AHViMKH2CQpGIpFgdHIEQsxwm8yCscqKmzbRA= github.com/coder/quartz v0.1.3/go.mod h1:vsiCc+AHViMKH2CQpGIpFgdHIEQsxwm8yCscqKmzbRA=
github.com/coder/retry v1.5.1 h1:iWu8YnD8YqHs3XwqrqsjoBTAVqT9ml6z9ViJ2wlMiqc= github.com/coder/retry v1.5.1 h1:iWu8YnD8YqHs3XwqrqsjoBTAVqT9ml6z9ViJ2wlMiqc=
@ -921,8 +921,8 @@ github.com/coder/tailscale v1.1.1-0.20250422090654-5090e715905e h1:nope/SZfoLB9M
github.com/coder/tailscale v1.1.1-0.20250422090654-5090e715905e/go.mod h1:1ggFFdHTRjPRu9Yc1yA7nVHBYB50w9Ce7VIXNqcW6Ko= github.com/coder/tailscale v1.1.1-0.20250422090654-5090e715905e/go.mod h1:1ggFFdHTRjPRu9Yc1yA7nVHBYB50w9Ce7VIXNqcW6Ko=
github.com/coder/terraform-config-inspect v0.0.0-20250107175719-6d06d90c630e h1:JNLPDi2P73laR1oAclY6jWzAbucf70ASAvf5mh2cME0= github.com/coder/terraform-config-inspect v0.0.0-20250107175719-6d06d90c630e h1:JNLPDi2P73laR1oAclY6jWzAbucf70ASAvf5mh2cME0=
github.com/coder/terraform-config-inspect v0.0.0-20250107175719-6d06d90c630e/go.mod h1:Gz/z9Hbn+4KSp8A2FBtNszfLSdT2Tn/uAKGuVqqWmDI= github.com/coder/terraform-config-inspect v0.0.0-20250107175719-6d06d90c630e/go.mod h1:Gz/z9Hbn+4KSp8A2FBtNszfLSdT2Tn/uAKGuVqqWmDI=
github.com/coder/terraform-provider-coder/v2 v2.4.0-pre1.0.20250417100258-c86bb5c3ddcd h1:FsIG6Fd0YOEK7D0Hl/CJywRA+Y6Gd5RQbSIa2L+/BmE= github.com/coder/terraform-provider-coder/v2 v2.4.0 h1:uuFmF03IyahAZLXEukOdmvV9hGfUMJSESD8+G5wkTcM=
github.com/coder/terraform-provider-coder/v2 v2.4.0-pre1.0.20250417100258-c86bb5c3ddcd/go.mod h1:56/KdGYaA+VbwXJbTI8CA57XPfnuTxN8rjxbR34PbZw= github.com/coder/terraform-provider-coder/v2 v2.4.0/go.mod h1:2kaBpn5k9ZWtgKq5k4JbkVZG9DzEqR4mJSmpdshcO+s=
github.com/coder/trivy v0.0.0-20250409153844-e6b004bc465a h1:yryP7e+IQUAArlycH4hQrjXQ64eRNbxsV5/wuVXHgME= github.com/coder/trivy v0.0.0-20250409153844-e6b004bc465a h1:yryP7e+IQUAArlycH4hQrjXQ64eRNbxsV5/wuVXHgME=
github.com/coder/trivy v0.0.0-20250409153844-e6b004bc465a/go.mod h1:dDvq9axp3kZsT63gY2Znd1iwzfqDq3kXbQnccIrjRYY= github.com/coder/trivy v0.0.0-20250409153844-e6b004bc465a/go.mod h1:dDvq9axp3kZsT63gY2Znd1iwzfqDq3kXbQnccIrjRYY=
github.com/coder/websocket v1.8.13 h1:f3QZdXy7uGVz+4uCJy2nTZyM0yTBj8yANEHhqlXZ9FE= github.com/coder/websocket v1.8.13 h1:f3QZdXy7uGVz+4uCJy2nTZyM0yTBj8yANEHhqlXZ9FE=

View File

@ -749,13 +749,17 @@ func ConvertState(ctx context.Context, modules []*tfjson.StateModule, rawGraph s
if err != nil { if err != nil {
return nil, xerrors.Errorf("decode map values for coder_parameter.%s: %w", resource.Name, err) return nil, xerrors.Errorf("decode map values for coder_parameter.%s: %w", resource.Name, err)
} }
var defaultVal string
if param.Default != nil {
defaultVal = *param.Default
}
protoParam := &proto.RichParameter{ protoParam := &proto.RichParameter{
Name: param.Name, Name: param.Name,
DisplayName: param.DisplayName, DisplayName: param.DisplayName,
Description: param.Description, Description: param.Description,
Type: param.Type, Type: param.Type,
Mutable: param.Mutable, Mutable: param.Mutable,
DefaultValue: param.Default, DefaultValue: defaultVal,
Icon: param.Icon, Icon: param.Icon,
Required: !param.Optional, Required: !param.Optional,
// #nosec G115 - Safe conversion as parameter order value is expected to be within int32 range // #nosec G115 - Safe conversion as parameter order value is expected to be within int32 range

View File

@ -1832,7 +1832,6 @@ export interface PreviewParameterValidation {
readonly validation_min: number | null; readonly validation_min: number | null;
readonly validation_max: number | null; readonly validation_max: number | null;
readonly validation_monotonic: string | null; readonly validation_monotonic: string | null;
readonly validation_invalid: boolean | null;
} }
// From codersdk/deployment.go // From codersdk/deployment.go