- Notifications
You must be signed in to change notification settings - Fork909
fix: use minDisabled, maxDisabled for parameter validation#7755
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
ff552ba
2059dd3
bded329
c7ab830
38b5d92
6d24ad6
85a7bd3
8cc120d
3dc0474
0976148
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 |
---|---|---|
@@ -483,8 +483,35 @@ func ConvertState(modules []*tfjson.StateModule, rawGraph string, rawParameterNa | ||
if len(param.Validation) == 1 { | ||
protoParam.ValidationRegex = param.Validation[0].Regex | ||
protoParam.ValidationError = param.Validation[0].Error | ||
validationAttributeValues, ok := resource.AttributeValues["validation"] | ||
if ok { | ||
validationAttributeValuesArr, ok := validationAttributeValues.([]interface{}) | ||
if ok { | ||
validationAttributeValuesMapStr, ok := validationAttributeValuesArr[0].(map[string]interface{}) | ||
if ok { | ||
// Backward compatibility with terraform-coder-plugin < v0.8.2: | ||
// * "min_disabled" and "max_disabled" are not available yet | ||
// * "min" and "max" are required to be specified together | ||
if _, ok = validationAttributeValuesMapStr["min_disabled"]; !ok { | ||
if param.Validation[0].Min != 0 || param.Validation[0].Max != 0 { | ||
param.Validation[0].MinDisabled = false | ||
param.Validation[0].MaxDisabled = false | ||
} else { | ||
param.Validation[0].MinDisabled = true | ||
param.Validation[0].MaxDisabled = true | ||
} | ||
} | ||
} | ||
} | ||
} | ||
mtojek marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
if !param.Validation[0].MaxDisabled { | ||
protoParam.ValidationMax = PtrInt32(param.Validation[0].Max) | ||
} | ||
if !param.Validation[0].MinDisabled { | ||
protoParam.ValidationMin = PtrInt32(param.Validation[0].Min) | ||
} | ||
protoParam.ValidationMonotonic = param.Validation[0].Monotonic | ||
} | ||
if len(param.Option) > 0 { | ||
@@ -527,12 +554,8 @@ func ConvertState(modules []*tfjson.StateModule, rawGraph string, rawParameterNa | ||
}, nil | ||
} | ||
func PtrInt32(number int) *int32 { | ||
n := int32(number) | ||
return &n | ||
} | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
terraform { | ||
required_providers { | ||
coder = { | ||
source = "coder/coder" | ||
version = "0.8.2" | ||
} | ||
} | ||
} | ||
data "coder_parameter" "number_example_min_max" { | ||
name = "number_example_min_max" | ||
type = "number" | ||
default = 4 | ||
validation { | ||
min = 3 | ||
max = 6 | ||
} | ||
} | ||
data "coder_parameter" "number_example_min" { | ||
name = "number_example_min" | ||
type = "number" | ||
default = 4 | ||
validation { | ||
min = 3 | ||
} | ||
} | ||
data "coder_parameter" "number_example_min_zero" { | ||
name = "number_example_min_zero" | ||
type = "number" | ||
default = 4 | ||
validation { | ||
min = 0 | ||
} | ||
} | ||
data "coder_parameter" "number_example_max" { | ||
name = "number_example_max" | ||
type = "number" | ||
default = 4 | ||
validation { | ||
max = 6 | ||
mtojek marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
} | ||
} | ||
data "coder_parameter" "number_example_max_zero" { | ||
name = "number_example_max_zero" | ||
type = "number" | ||
default = -3 | ||
validation { | ||
max = 0 | ||
} | ||
} | ||
data "coder_parameter" "number_example" { | ||
name = "number_example" | ||
type = "number" | ||
default = 4 | ||
} | ||
resource "coder_agent" "dev" { | ||
os = "windows" | ||
arch = "arm64" | ||
} | ||
resource "null_resource" "dev" { | ||
depends_on = [coder_agent.dev] | ||
} |
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.
Uh oh!
There was an error while loading.Please reload this page.