@@ -593,30 +593,42 @@ func (b *Builder) getParameters() (names, values []string, err error) {
593
593
return nil , nil , BuildError {http .StatusBadRequest , "Unable to build workspace with unsupported parameters" , err }
594
594
}
595
595
596
+ if b .dynamicParametersEnabled {
597
+ // Dynamic parameters skip all parameter validation.
598
+ // Pass the user's input as is.
599
+ // TODO: The previous behavior was only to pass param values
600
+ // for parameters that exist. Since dynamic params can have
601
+ // conditional parameter existence, the static frame of reference
602
+ // is not sufficient. So assume the user is correct, or pull in the
603
+ // dynamic param code to find the actual parameters.
604
+ for _ , value := range b .richParameterValues {
605
+ names = append (names , value .Name )
606
+ values = append (values , value .Value )
607
+ }
608
+ b .parameterNames = & names
609
+ b .parameterValues = & values
610
+ return names , values , nil
611
+ }
612
+
596
613
resolver := codersdk.ParameterResolver {
597
614
Rich : db2sdk .WorkspaceBuildParameters (lastBuildParameters ),
598
615
}
616
+
599
617
for _ , templateVersionParameter := range templateVersionParameters {
600
618
tvp , err := db2sdk .TemplateVersionParameter (templateVersionParameter )
601
619
if err != nil {
602
620
return nil , nil , BuildError {http .StatusInternalServerError , "failed to convert template version parameter" , err }
603
621
}
604
622
605
- var value string
606
- if ! b .dynamicParametersEnabled {
607
- var err error
608
- value , err = resolver .ValidateResolve (
609
- tvp ,
610
- b .findNewBuildParameterValue (templateVersionParameter .Name ),
611
- )
612
- if err != nil {
613
- // At this point, we've queried all the data we need from the database,
614
- // so the only errors are problems with the request (missing data, failed
615
- // validation, immutable parameters, etc.)
616
- return nil , nil , BuildError {http .StatusBadRequest , fmt .Sprintf ("Unable to validate parameter %q" , templateVersionParameter .Name ), err }
617
- }
618
- } else {
619
- value = resolver .Resolve (tvp , b .findNewBuildParameterValue (templateVersionParameter .Name ))
623
+ value , err := resolver .ValidateResolve (
624
+ tvp ,
625
+ b .findNewBuildParameterValue (templateVersionParameter .Name ),
626
+ )
627
+ if err != nil {
628
+ // At this point, we've queried all the data we need from the database,
629
+ // so the only errors are problems with the request (missing data, failed
630
+ // validation, immutable parameters, etc.)
631
+ return nil , nil , BuildError {http .StatusBadRequest , fmt .Sprintf ("Unable to validate parameter %q" , templateVersionParameter .Name ), err }
620
632
}
621
633
622
634
names = append (names , templateVersionParameter .Name )
0 commit comments