Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5f4b94b

Browse files
committed
pseudocode: max_ok, min_ok
1 parent0d0a3c8 commit5f4b94b

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

‎provider/parameter.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@ type Option struct {
2828
}
2929

3030
typeValidationstruct {
31-
Min*int
32-
Max*int
31+
Min*int
32+
MinOkbool`mapstructure:"min_ok"`
33+
Max*int
34+
MaxOkbool`mapstructure:"max_ok"`
35+
3336
Monotonicstring
3437

3538
Regexstring
@@ -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
ifrawValidationRule["min"].IsNull() {
368381
validationRule["min"]=nil
382+
validationRule["min_ok"]=false
383+
}else {
384+
validationRule["min_ok"]=true
369385
}
370386
ifrawValidationRule["max"].IsNull() {
371387
validationRule["max"]=nil
388+
validationRule["max_ok"]=false
389+
}else {
390+
validationRule["max_ok"]=true
372391
}
373392
returnvArr,nil
374393
}

‎provider/parameter_test.go

Lines changed: 7 additions & 10 deletions
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
forkey,expected:=rangemap[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)

[8]ページ先頭

©2009-2025 Movatter.jp