diff --git a/helper/schema/schema.go b/helper/schema/schema.go index c05de7a5b..c3ce44874 100644 --- a/helper/schema/schema.go +++ b/helper/schema/schema.go @@ -12,7 +12,7 @@ type ValueType int const ( TypeInvalid ValueType = iota - TypeBoolean + TypeBool TypeInt TypeString TypeList @@ -67,8 +67,14 @@ func (m schemaMap) Diff( var err error switch schema.Type { + case TypeBool: + fallthrough + case TypeInt: + fallthrough case TypeString: attrD, err = m.diffString(k, schema, s, c) + default: + err = fmt.Errorf("%s: unknown type %s", k, schema.Type) } if err != nil { diff --git a/helper/schema/schema_test.go b/helper/schema/schema_test.go index b93d5e2eb..d30ffbbfc 100644 --- a/helper/schema/schema_test.go +++ b/helper/schema/schema_test.go @@ -16,6 +16,10 @@ func TestSchemaMap_Diff(t *testing.T) { Diff *terraform.ResourceDiff Err bool }{ + /* + * String decode + */ + { Schema: map[string]*Schema{ "availability_zone": &Schema{ @@ -88,6 +92,72 @@ func TestSchemaMap_Diff(t *testing.T) { Err: true, }, + + /* + * Int decode + */ + + { + Schema: map[string]*Schema{ + "port": &Schema{ + Type: TypeInt, + Optional: true, + Computed: true, + ForceNew: true, + }, + }, + + State: nil, + + Config: map[string]interface{}{ + "port": 27, + }, + + Diff: &terraform.ResourceDiff{ + Attributes: map[string]*terraform.ResourceAttrDiff{ + "port": &terraform.ResourceAttrDiff{ + Old: "", + New: "27", + RequiresNew: true, + }, + }, + }, + + Err: false, + }, + + /* + * Bool decode + */ + + { + Schema: map[string]*Schema{ + "port": &Schema{ + Type: TypeBool, + Optional: true, + Computed: true, + ForceNew: true, + }, + }, + + State: nil, + + Config: map[string]interface{}{ + "port": false, + }, + + Diff: &terraform.ResourceDiff{ + Attributes: map[string]*terraform.ResourceAttrDiff{ + "port": &terraform.ResourceAttrDiff{ + Old: "", + New: "0", + RequiresNew: true, + }, + }, + }, + + Err: false, + }, } for i, tc := range cases {