helper/schema: validate string/bool types [GH-460]
This commit is contained in:
parent
a44de4b96b
commit
3e1169db61
|
@ -10,6 +10,7 @@ BUG FIXES:
|
||||||
* core: If a resource fails to create and has provisioners, it is
|
* core: If a resource fails to create and has provisioners, it is
|
||||||
marked as tainted. [GH-434]
|
marked as tainted. [GH-434]
|
||||||
* core: Set types are validated to be sets. [GH-413]
|
* core: Set types are validated to be sets. [GH-413]
|
||||||
|
* core: String types are validated properly. [GH-460]
|
||||||
* core: Fix crash case when destroying with tainted resources. [GH-412]
|
* core: Fix crash case when destroying with tainted resources. [GH-412]
|
||||||
* core: Don't execute provisioners in some cases on destroy.
|
* core: Don't execute provisioners in some cases on destroy.
|
||||||
* core: Inherited provider configurations will be properly interpolated. [GH-418]
|
* core: Inherited provider configurations will be properly interpolated. [GH-418]
|
||||||
|
|
|
@ -823,12 +823,26 @@ func (m schemaMap) validatePrimitive(
|
||||||
fallthrough
|
fallthrough
|
||||||
case TypeList:
|
case TypeList:
|
||||||
return m.validateList(k, raw, schema, c)
|
return m.validateList(k, raw, schema, c)
|
||||||
|
case TypeBool:
|
||||||
|
// Verify that we can parse this as the correct type
|
||||||
|
var n bool
|
||||||
|
if err := mapstructure.WeakDecode(raw, &n); err != nil {
|
||||||
|
return nil, []error{err}
|
||||||
|
}
|
||||||
case TypeInt:
|
case TypeInt:
|
||||||
// Verify that we can parse this as an int
|
// Verify that we can parse this as an int
|
||||||
var n int
|
var n int
|
||||||
if err := mapstructure.WeakDecode(raw, &n); err != nil {
|
if err := mapstructure.WeakDecode(raw, &n); err != nil {
|
||||||
return nil, []error{err}
|
return nil, []error{err}
|
||||||
}
|
}
|
||||||
|
case TypeString:
|
||||||
|
// Verify that we can parse this as a string
|
||||||
|
var n string
|
||||||
|
if err := mapstructure.WeakDecode(raw, &n); err != nil {
|
||||||
|
return nil, []error{err}
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
panic(fmt.Sprintf("Unknown validation type: %s", schema.Type))
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
|
|
@ -1788,6 +1788,25 @@ func TestSchemaMap_Validate(t *testing.T) {
|
||||||
Err: true,
|
Err: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
Schema: map[string]*Schema{
|
||||||
|
"user_data": &Schema{
|
||||||
|
Type: TypeString,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
Config: map[string]interface{}{
|
||||||
|
"user_data": []interface{}{
|
||||||
|
map[string]interface{}{
|
||||||
|
"foo": "bar",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
Err: true,
|
||||||
|
},
|
||||||
|
|
||||||
// Bad type, interpolated
|
// Bad type, interpolated
|
||||||
{
|
{
|
||||||
Schema: map[string]*Schema{
|
Schema: map[string]*Schema{
|
||||||
|
|
Loading…
Reference in New Issue