helper/schema: one of Optional, Required, Computed must be set
This commit is contained in:
parent
fb9d62e27a
commit
31cc3ffca1
|
@ -78,6 +78,10 @@ type SchemaSetFunc func(interface{}) int
|
|||
// to be stored in the state.
|
||||
type SchemaStateFunc func(interface{}) string
|
||||
|
||||
func (s *Schema) GoString() string {
|
||||
return fmt.Sprintf("*%#v", *s)
|
||||
}
|
||||
|
||||
func (s *Schema) finalizeDiff(
|
||||
d *terraform.ResourceAttrDiff) *terraform.ResourceAttrDiff {
|
||||
if d == nil {
|
||||
|
@ -184,6 +188,10 @@ func (m schemaMap) InternalValidate() error {
|
|||
return fmt.Errorf("%s: Cannot be both Required and Computed", k)
|
||||
}
|
||||
|
||||
if !v.Required && !v.Optional && !v.Computed {
|
||||
return fmt.Errorf("%s: One of optional, required, or computed must be set", k)
|
||||
}
|
||||
|
||||
if len(v.ComputedWhen) > 0 && !v.Computed {
|
||||
return fmt.Errorf("%s: ComputedWhen can only be set with Computed", k)
|
||||
}
|
||||
|
|
|
@ -780,6 +780,16 @@ func TestSchemaMap_InternalValidate(t *testing.T) {
|
|||
true,
|
||||
},
|
||||
|
||||
// No optional and no required
|
||||
{
|
||||
map[string]*Schema{
|
||||
"foo": &Schema{
|
||||
Type: TypeInt,
|
||||
},
|
||||
},
|
||||
true,
|
||||
},
|
||||
|
||||
// Missing Type
|
||||
{
|
||||
map[string]*Schema{
|
||||
|
@ -828,6 +838,7 @@ func TestSchemaMap_InternalValidate(t *testing.T) {
|
|||
map[string]*Schema{
|
||||
"foo": &Schema{
|
||||
Type: TypeList,
|
||||
Optional: true,
|
||||
Elem: &Schema{
|
||||
Type: TypeInt,
|
||||
Computed: true,
|
||||
|
@ -844,6 +855,7 @@ func TestSchemaMap_InternalValidate(t *testing.T) {
|
|||
Type: TypeList,
|
||||
Elem: &Schema{Type: TypeInt},
|
||||
Set: func(interface{}) int { return 0 },
|
||||
Optional: true,
|
||||
},
|
||||
},
|
||||
true,
|
||||
|
@ -855,6 +867,7 @@ func TestSchemaMap_InternalValidate(t *testing.T) {
|
|||
"foo": &Schema{
|
||||
Type: TypeSet,
|
||||
Elem: &Schema{Type: TypeInt},
|
||||
Optional: true,
|
||||
},
|
||||
},
|
||||
true,
|
||||
|
@ -877,6 +890,7 @@ func TestSchemaMap_InternalValidate(t *testing.T) {
|
|||
map[string]*Schema{
|
||||
"foo": &Schema{
|
||||
Type: TypeList,
|
||||
Optional: true,
|
||||
Elem: &Resource{
|
||||
Schema: map[string]*Schema{
|
||||
"foo": new(Schema),
|
||||
|
@ -892,10 +906,12 @@ func TestSchemaMap_InternalValidate(t *testing.T) {
|
|||
map[string]*Schema{
|
||||
"foo": &Schema{
|
||||
Type: TypeList,
|
||||
Optional: true,
|
||||
Elem: &Resource{
|
||||
Schema: map[string]*Schema{
|
||||
"foo": &Schema{
|
||||
Type: TypeInt,
|
||||
Optional: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -908,7 +924,7 @@ func TestSchemaMap_InternalValidate(t *testing.T) {
|
|||
for i, tc := range cases {
|
||||
err := schemaMap(tc.In).InternalValidate()
|
||||
if (err != nil) != tc.Err {
|
||||
t.Fatalf("%d: bad: %s", i, err)
|
||||
t.Fatalf("%d: bad: %s\n\n%#v", i, err, tc.In)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue