Skip to content

Commit 5f4b94b

Browse files
committed
pseudocode: max_ok, min_ok
1 parent 0d0a3c8 commit 5f4b94b

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

provider/parameter.go

+21-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@ type Option struct {
2828
}
2929

3030
type Validation struct {
31-
Min *int
32-
Max *int
31+
Min *int
32+
MinOk bool `mapstructure:"min_ok"`
33+
Max *int
34+
MaxOk bool `mapstructure:"max_ok"`
35+
3336
Monotonic string
3437

3538
Regex string
@@ -288,11 +291,21 @@ func parameterDataSource() *schema.Resource {
288291
Optional: true,
289292
Description: "The minimum of a number parameter.",
290293
},
294+
"min_ok": {
295+
Type: schema.TypeBool,
296+
Computed: true,
297+
Description: "Helper field to check if min is present",
298+
},
291299
"max": {
292300
Type: schema.TypeInt,
293301
Optional: true,
294302
Description: "The maximum of a number parameter.",
295303
},
304+
"max_ok": {
305+
Type: schema.TypeBool,
306+
Computed: true,
307+
Description: "Helper field to check if max is present",
308+
},
296309
"monotonic": {
297310
Type: schema.TypeString,
298311
Optional: true,
@@ -366,9 +379,15 @@ func fixValidationResourceData(rawConfig cty.Value, validation interface{}) (int
366379
// Fix the resource data
367380
if rawValidationRule["min"].IsNull() {
368381
validationRule["min"] = nil
382+
validationRule["min_ok"] = false
383+
} else {
384+
validationRule["min_ok"] = true
369385
}
370386
if rawValidationRule["max"].IsNull() {
371387
validationRule["max"] = nil
388+
validationRule["max_ok"] = false
389+
} else {
390+
validationRule["max_ok"] = true
372391
}
373392
return vArr, nil
374393
}

provider/parameter_test.go

+7-10
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,16 @@ func TestParameter(t *testing.T) {
3232
`,
3333
Check: func(state *terraform.ResourceState) {
3434
for key, expected := range map[string]string{
35-
"name": "Region",
36-
"type": "number",
37-
"validation.#": "1",
38-
"default": "2",
39-
"validation.0.max": "9",
35+
"name": "Region",
36+
"type": "number",
37+
"validation.#": "1",
38+
"default": "2",
39+
"validation.0.max": "9",
40+
"validation.0.min_ok": "false",
41+
"validation.0.max_ok": "true",
4042
} {
4143
require.Equal(t, expected, state.Primary.Attributes[key])
4244
}
43-
44-
_, foundDisplayName := state.Primary.Attributes["display_name"]
45-
require.False(t, foundDisplayName, "display_name = "+state.Primary.Attributes["display_name"])
46-
_, foundValidationMin := state.Primary.Attributes["validation.0.min"]
47-
require.False(t, foundValidationMin, "validation.0.min = "+state.Primary.Attributes["validation.0.min"])
4845
},
4946
}, {
5047
Name: "FieldsExist",

0 commit comments

Comments
 (0)