helper/schema: record schema version when destroy fails

This was just a missed exit from the resource.Apply function -
subsequent refreshes would add the SchemaVersion back into the state,
but having the state recorded once without the meta information can
cause problems with Atlas's remote state checksumming.
This commit is contained in:
Paul Hinze 2015-08-03 15:52:04 -05:00
parent 2cea7c7d0c
commit 7eb72e7a12
2 changed files with 6 additions and 2 deletions

View File

@ -119,7 +119,7 @@ func (r *Resource) Apply(
if s.ID != "" {
// Destroy the resource since it is created
if err := r.Delete(data, meta); err != nil {
return data.State(), err
return r.recordCurrentSchemaVersion(data.State()), err
}
// Make sure the ID is gone.

View File

@ -180,6 +180,7 @@ func TestResourceApply_destroyPartial(t *testing.T) {
Optional: true,
},
},
SchemaVersion: 3,
}
r.Delete = func(d *ResourceData, m interface{}) error {
@ -209,10 +210,13 @@ func TestResourceApply_destroyPartial(t *testing.T) {
"id": "bar",
"foo": "42",
},
Meta: map[string]string{
"schema_version": "3",
},
}
if !reflect.DeepEqual(actual, expected) {
t.Fatalf("bad: %#v", actual)
t.Fatalf("expected:\n%#v\n\ngot:\n%#v", expected, actual)
}
}