diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b19e0d51..bb0dfc47e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ BUG FIXES: * core: Remove panic case when applying with a plan that generates no new state. [GH-403] * 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) diff --git a/helper/schema/schema.go b/helper/schema/schema.go index 7e26741ff..d074e9512 100644 --- a/helper/schema/schema.go +++ b/helper/schema/schema.go @@ -813,6 +813,11 @@ func (m schemaMap) validatePrimitive( raw interface{}, schema *Schema, 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 { case TypeList: return m.validateList(k, raw, schema, c) diff --git a/helper/schema/schema_test.go b/helper/schema/schema_test.go index d25ce32d0..66830869c 100644 --- a/helper/schema/schema_test.go +++ b/helper/schema/schema_test.go @@ -1720,6 +1720,7 @@ func TestSchemaMap_Validate(t *testing.T) { cases := []struct { Schema map[string]*Schema Config map[string]interface{} + Vars map[string]string Warn 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 { Schema: map[string]*Schema{ @@ -1769,6 +1788,26 @@ func TestSchemaMap_Validate(t *testing.T) { 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 { Schema: map[string]*Schema{ @@ -1938,6 +1977,11 @@ func TestSchemaMap_Validate(t *testing.T) { if err != nil { 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)) if (len(es) > 0) != tc.Err {