helper/schema: valiate should ignore computed fields

This commit is contained in:
Mitchell Hashimoto 2014-10-16 14:04:45 -07:00
parent bb2e33682d
commit 2e703afdad
3 changed files with 51 additions and 0 deletions

View File

@ -5,6 +5,8 @@ BUG FIXES:
* core: Remove panic case when applying with a plan that generates no * core: Remove panic case when applying with a plan that generates no
new state. [GH-403] new state. [GH-403]
* core: Fix a hang that can occur with enough resources. [GH-410] * core: Fix a hang that can occur with enough resources. [GH-410]
* core: Config validation will not error if the field is being
computed so the value is still unknown.
## 0.3.0 (October 14, 2014) ## 0.3.0 (October 14, 2014)

View File

@ -813,6 +813,11 @@ func (m schemaMap) validatePrimitive(
raw interface{}, raw interface{},
schema *Schema, schema *Schema,
c *terraform.ResourceConfig) ([]string, []error) { c *terraform.ResourceConfig) ([]string, []error) {
if c.IsComputed(k) {
// If the key is being computed, then it is not an error
return nil, nil
}
switch schema.Type { switch schema.Type {
case TypeList: case TypeList:
return m.validateList(k, raw, schema, c) return m.validateList(k, raw, schema, c)

View File

@ -1720,6 +1720,7 @@ func TestSchemaMap_Validate(t *testing.T) {
cases := []struct { cases := []struct {
Schema map[string]*Schema Schema map[string]*Schema
Config map[string]interface{} Config map[string]interface{}
Vars map[string]string
Warn bool Warn bool
Err bool Err bool
}{ }{
@ -1739,6 +1740,24 @@ func TestSchemaMap_Validate(t *testing.T) {
}, },
}, },
// Good, because the var is not set and that error will come elsewhere
{
Schema: map[string]*Schema{
"size": &Schema{
Type: TypeInt,
Required: true,
},
},
Config: map[string]interface{}{
"size": "${var.foo}",
},
Vars: map[string]string{
"var.foo": config.UnknownVariableValue,
},
},
// Required field not set // Required field not set
{ {
Schema: map[string]*Schema{ Schema: map[string]*Schema{
@ -1769,6 +1788,26 @@ func TestSchemaMap_Validate(t *testing.T) {
Err: true, Err: true,
}, },
// Bad type, interpolated
{
Schema: map[string]*Schema{
"size": &Schema{
Type: TypeInt,
Required: true,
},
},
Config: map[string]interface{}{
"size": "${var.foo}",
},
Vars: map[string]string{
"var.foo": "nope",
},
Err: true,
},
// Required but has DefaultFunc // Required but has DefaultFunc
{ {
Schema: map[string]*Schema{ Schema: map[string]*Schema{
@ -1938,6 +1977,11 @@ func TestSchemaMap_Validate(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
if tc.Vars != nil {
if err := c.Interpolate(tc.Vars); err != nil {
t.Fatalf("err: %s", err)
}
}
ws, es := schemaMap(tc.Schema).Validate(terraform.NewResourceConfig(c)) ws, es := schemaMap(tc.Schema).Validate(terraform.NewResourceConfig(c))
if (len(es) > 0) != tc.Err { if (len(es) > 0) != tc.Err {